I have a BufferedImage (Type.TYPE_INT_ARGB) that I want to convert to a int[]. I do this by using the following method:
((DataBufferInt)src.getRaster().getDataBuffer()).getData();. But when I do this with an image, it gives me the wrong array size. For a 320 x 240 Image it makes a 57,600 size int[] when it should give me a 78,600 size array. Do you know what I am doing wrong?
Add a comment
|
1 Answer
What's wrong with
src.getRGB(0,0,image.getWidth(),image.getHeight(),null,0,1);
5 Comments
TameHog
I just use this way because it is the first way I learned. I'll try that now.
user2282497
"That didn't work" is not helpful. Have a look at the javadoc and play with the parameters a bit - I don't have your code.
TameHog
It turns out that the source image is supposed to be 320x240 but it is 240x240. My bad
Maarten Bodewes
Ugh. And I though I was up late.
Harald K
It's slow, that's what's wrong with it. :-) (It's not a bad suggestion though, as it will always give the expected results, but at the expense of possible extra color conversion and always array copy).