>
> Basically, if you create a TYPE_INT_RGB, or
> TYPE_INT_ARGB, then it will
> have 1 Raster with 1 DataBuffer with 1 array of int[]
> that is large
> enough for every pixel in the image.
I was browsing through some old threads and ran across this one. Just thought
I'd mention a problem I found.
I do what Jim suggested -- sort of -- and it works well. The reason I use a
MemoryImage Source is that it's a very simple way to stuff pixels into an
image. Just build your int array with your pixels and tell MemoryImageSource
that it now has new pixels to update. In my applet, the most time consuming
computation is calculating the mapping from the source image to the projected
image. It takes O(100ms) per frame to do that. The time difference between
displaying the calculated pixels with BI or MIS is negligible .
ImageReadParam irp = new ImageReadParam();
BufferedImage bi = null;
ImageInputStream iis = ImageIO.createImageInputStream(new
ByteArrayInputStream(imageBuffer));
reader.setInput(iis, true);
width = reader.getWidth(0);
height = reader.getHeight(0);
bi = new BufferedImage(width,height,BufferedImage.TYPE_INT_RGB);
irp.setDestination(bi);
bi = reader.read(0,irp);
pixels =
((DataBufferInt)(bi.getRaster().getDataBuffer())).getData();
for(int i = 0,j = 0; i < pixels.length; i++,j+=3)
pixels[i] |= 0xff000000;
Two things to note:
1) Using TYPE_INT_ARGB causes this code fragment to fail. But I'm using
1.5.0_15
bi = new BufferedImage(width,height,BufferedImage.TYPE_INT_ARGB);
irp.setDestination(bi);
bi = reader.read(0,irp);
java.lang.IllegalArgumentException: ImageReadParam num source & dest bands
differ!
at
javax.imageio.ImageReader.checkReadParamBandSettings(ImageReader.java:2746)
at
com.sun.imageio.plugins.jpeg.JPEGImageReader.readInternal(JPEGImageReader.java:907)
at
com.sun.imageio.plugins.jpeg.JPEGImageReader.read(JPEGImageReader.java:864)
at
pangnomic.PanGnomicImageFetch.makeBufferedImage(PanGnomicImageFetch.java:211)
at pangnomic.PanGnomicImageFetch.run(PanGnomicImageFetch.java:299)
at java.lang.Thread.run(Thread.java:595)
2) The pixels from the DataBufferInt have the alpha channel initialized to 0.
Giving an int array of pixels with the alpha channel initialized to 0 to the
MIS will render as a wholly transparent image.
These are things that I see in my applet with 1.5.0_15 and I suppose these
things have been changed in 1.6.0.X. Just thought I'd mention it.
If you want to think about what I mean by " calculating the mapping from the
source image to the projected image ". Look at the image in my viewer -- then
look at the image. See how things like the railing are straight in the viewer
and curved in the image. That's the mapping. And it is way more
computationally expensive and complicated than pushing pixels here and there so
I opted for simple code and MIS is the simplest.
http://pancyl.com/Motel.htm
http://pancyl.com/images/Motel.jpg
[Message sent by forum member 'demonduck' (demonduck)]
http://forums.java.net/jive/thread.jspa?messageID=349881
===========================================================================
To unsubscribe, send email to [email protected] and include in the body
of the message "signoff JAVA2D-INTEREST". For general help, send email to
[email protected] and include in the body of the message "help".