I'm new to Java and right now I'm trying to get an image zoomed in 2x on a specific corner. Currently I have this method that needs to be changed. On the right is the original Image, on the left is the result I need to have, the left corned is the one zoomed in 2x. What should I change in order to get the result I want? Thanks in advance!
public static BufferedImage zoomImage(BufferedImage image) {
int height = image.getHeight();
int width = image.getWidth();
for (int y = 0; y < height; y++) {
for (int x = 0; x < width; x++) {
int pixelRGB = image.getRGB(x, y);
int newPixelColor = pixelRGB;
image.setRGB(width, y, newPixelColor);
}
}
return image;
}
答案 0 :(得分:0)
您希望将原始图像左上角四分之一的每个像素转换为新图像中的4个像素,直到填满缓冲区为止。但是,您会发现从左上角开始意味着您在读取之前会覆盖中间附近的像素。你应该从中间开始;将颜色应用于右下角的2x2方块。然后重复相同的过程,向上和向左前进。最后一个操作是使左上方的2x2方形与左上方的像素颜色相同。