문제

I'm having a really bad time dealing with RGB values in Java, which made me start trying small experiments with this.

I came down to this: loading an image, get it's rgb values and creating a new image with the same values. Unfortunately, this does not work (the images are displayed differently, see picture), as per the following code... Can some one see what's wrong?

BufferedImage oriImage=ImageIO.read(new  URL("http://upload.wikimedia.org/wikipedia/en/2/24/Lenna.png"));

int[] oriImageAsIntArray = new int[oriImage.getWidth()*oriImage.getHeight()];
oriImage.getRGB(0, 0, oriImage.getWidth(),oriImage.getHeight(), oriImageAsIntArray, 0, 1);

BufferedImage bfImage= new BufferedImage(oriImage.getWidth(),oriImage.getHeight(),
            BufferedImage.TYPE_INT_ARGB);

bfImage.setRGB(0,0,bfImage.getWidth(),bfImage.getHeight(),oriImageAsIntArray, 0, 1);

output

올바른 솔루션이 없습니다

다른 팁

Apparently, getRGB and setRGB were not being used correctly.

I changed the code to:

oriImage.getRGB(0, 0, oriImage.getWidth(),oriImage.getHeight(), oriImageAsIntArray, 0,  oriImage.getWidth());
(...)
bfImage.setRGB(0,0,bfImage.getWidth(),bfImage.getHeight(),oriImageAsIntArray, 0, bfImage.getWidth());

... and the picture displayed correctly. I still do not understand what this last argument is. In the JavaDoc, it is described as:

scansize - scanline stride for the rgbArray
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top