| 1 | package utils;
|
|---|
| 2 |
|
|---|
| 3 | import java.awt.image.ImageObserver;
|
|---|
| 4 | import java.awt.Image;
|
|---|
| 5 | import java.awt.Graphics;
|
|---|
| 6 | import java.awt.Color;
|
|---|
| 7 | import java.awt.image.BufferedImage;
|
|---|
| 8 |
|
|---|
| 9 | public class DynamicImage
|
|---|
| 10 | {
|
|---|
| 11 | private String filePath;
|
|---|
| 12 | private BufferedImage img;
|
|---|
| 13 | private Color bg;
|
|---|
| 14 | private Color shadow;
|
|---|
| 15 |
|
|---|
| 16 | public DynamicImage(final String filePath) {
|
|---|
| 17 | this.filePath = filePath;
|
|---|
| 18 | this.img = null;
|
|---|
| 19 | final Color color = null;
|
|---|
| 20 | this.shadow = color;
|
|---|
| 21 | this.bg = color;
|
|---|
| 22 | }
|
|---|
| 23 |
|
|---|
| 24 | public DynamicImage(final String filePath, final Color bg, final Color shadow) {
|
|---|
| 25 | this.filePath = filePath;
|
|---|
| 26 | this.img = null;
|
|---|
| 27 | this.bg = bg;
|
|---|
| 28 | this.shadow = shadow;
|
|---|
| 29 | }
|
|---|
| 30 |
|
|---|
| 31 | private void loadImg() {
|
|---|
| 32 | if (this.bg == null) {
|
|---|
| 33 | this.img = Utils.loadImg(this.filePath);
|
|---|
| 34 | }
|
|---|
| 35 | else {
|
|---|
| 36 | this.img = Utils.loadTransImg(this.filePath, this.bg, this.shadow);
|
|---|
| 37 | }
|
|---|
| 38 | }
|
|---|
| 39 |
|
|---|
| 40 | public int getHeight() {
|
|---|
| 41 | if (this.img == null) {
|
|---|
| 42 | this.loadImg();
|
|---|
| 43 | }
|
|---|
| 44 | return this.img.getHeight();
|
|---|
| 45 | }
|
|---|
| 46 |
|
|---|
| 47 | public int getWidth() {
|
|---|
| 48 | if (this.img == null) {
|
|---|
| 49 | this.loadImg();
|
|---|
| 50 | }
|
|---|
| 51 | return this.img.getWidth();
|
|---|
| 52 | }
|
|---|
| 53 |
|
|---|
| 54 | public void draw(final Graphics g, final int x, final int y) {
|
|---|
| 55 | if (this.img == null) {
|
|---|
| 56 | this.loadImg();
|
|---|
| 57 | }
|
|---|
| 58 | g.drawImage(this.img, x, y, null);
|
|---|
| 59 | }
|
|---|
| 60 |
|
|---|
| 61 | public void draw(final Graphics g, final int dx1, final int dy1, final int dx2, final int dy2, final int sx1, final int sy1, final int sx2, final int sy2) {
|
|---|
| 62 | if (this.img == null) {
|
|---|
| 63 | this.loadImg();
|
|---|
| 64 | }
|
|---|
| 65 | g.drawImage(this.img, dx1, dy1, dx2, dy2, sx1, sy1, sx2, sy2, null);
|
|---|
| 66 | }
|
|---|
| 67 | }
|
|---|