Image loading part 1

This commit is contained in:
Sebastian Cabrera 2019-08-29 02:34:50 -04:00
parent 8e7367dce8
commit ca8dfb9735
3 changed files with 67 additions and 0 deletions

View file

@ -2,6 +2,8 @@ package bz.bronze.pixels.engine;
import java.awt.image.DataBufferInt; import java.awt.image.DataBufferInt;
import bz.bronze.pixels.engine.gfx.Image;
public class Renderer { public class Renderer {
private int pW, pH; private int pW, pH;
private int[] p; private int[] p;
@ -23,4 +25,18 @@ public class Renderer {
p[i] = 0; p[i] = 0;
} }
} }
public void setPixel(int x, int y, int value) {
if ((x < 0 || x >= pW || y < 0 || y >= pH) || value == 0xffff00ff) {
return;
}
}
public void drawImage(Image image, int offX, int offY) {
for (int y = 0; y < image.getH(); y++) {
for (int x = 0; x < image.getW(); x++) {
}
}
}
} }

View file

@ -0,0 +1,51 @@
package bz.bronze.pixels.engine.gfx;
import java.awt.image.BufferedImage;
import java.io.IOException;
import javax.imageio.ImageIO;
public class Image {
private int w, h;
private int[] p;
public Image(String path) {
BufferedImage image = null;
try {
image = ImageIO.read(Image.class.getResourceAsStream(path));
} catch (IOException e) {
e.printStackTrace();
}
w = image.getWidth();
h = image.getHeight();
p = image.getRGB(0, 0, w, h, null, 0, w);
image.flush();
}
public int getW() {
return w;
}
public int getH() {
return h;
}
public int[] getP() {
return p;
}
public void setW(int w) {
this.w = w;
}
public void setH(int h) {
this.h = h;
}
public void setP(int[] p) {
this.p = p;
}
}