I'm sure this question has been asked numerous amounts of time, so my apologies. I'll be looking through previous answers, until someone replies to this. Or if I could get redirected to a solution.
When I use the method below, I get a pixel array of information, based on the data of a BufferedImage. But there's no way to change the width and height after the pixel data has been created...once you're running the game, that is. Basically, a 16x32 sprite, can't be upscaled to 32x64...or something weird, like 456x12. What's the better way to do this?
Here's my code:
import java.awt.image.BufferedImage;
import java.io.IOException;
import javax.imageio.ImageIO;
public class GameImage {
private int w, h;
private int[]p;
public GameImage(String path) {
BufferedImage image = null;
try {
image = ImageIO.read(GameImage.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 void setW(int w) {
this.w = w;
}
public int getH() {
return h;
}
public void setH(int h) {
this.h = h;
}
public int[] getP() {
return p;
}
public void setP(int[] p) {
this.p = p;
}
}
The image below shows my game screen on a "regular-sized" monitor. The sprite on screen is 16x32...it can't be upscaled. The blue background is a larger BufferedImage that the whole game is being rendered on. I use a RenderEngine object, and call methods like r.drawImage() to draw...images, lol. I'm sure you can guess...these images get drawn to the BufferedImage, that's made up of more pixel data.
(Not sure if this is the best method for game screens...but it seems to work for now.)
enter image description here
question from:
https://stackoverflow.com/questions/65928293/pixel-image-data-could-it-be-resized 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…