Thank you Dmitri for your answer. Let me just say a bit more of the problem and why i go to this method:
My goal is to find the faster way to load an image from the disk (a tif file, either binary or colored) and display it on the screen in a compatible way (e.g. fast to redraw, pan, zoom, etc). >From all the reading i have done, i have concluded that i need to: 1. Load the image with ImageIO 2. Convert it to compatible 3. Display. Point 2 is what takes more time (since i don't think i can optimize the time for reading). Here are some benchmarks: 1. Converting an image to a compatible one is always faster with a ColorConverOp than with a g.drawImage. At times the speed is the same, but in general, the ColorConverOp is always a bit faster. What is really interesting is this: if an images already uses a SinglePixelPackedSampleModel then the ColorConvertOp is significantly faster (more than 50%). 2. So the question remains: a. Is it faster to convert directly to compatible using g.drawImage, or b. is it faster to create an unmanageable image with a SinglePixelPackedSampleModel and then use the ColorConvertOp to make a compatible out of it? It seems that method-b is between 2-3 times faster than method-a for colored images! This is very impressive for me! For binary images, both methods provide similar results, but again method-b tends to be a bit faster (about 10%-20%). This is why i use it. My original thought was this then: "Since with the second method it is possible to create an image with the exact same characteristics of a compatible, why do i need to go through the step of converting to a compatible one?" You answered to me on that one: because the image is not manageable! So, i tried to modify my code and instead of creating the DataBuffer myself, i use the WriteableRaster to set the pixel values: but it seems that the time needed for the 'setSamples' method is bigger than method-b. So, it seems that no-matter what i do, still the fastest way is to create the DataBuffer myself and then convert to compatible image with the ColorConvertOp. It would be great if i could find a way to create a compatible image with my own DataBuffer that is also manageable (without another conversion/step). Is there a solution to this? Excuse me if some of the above comments are incorrect, but i am new to Java2D programming. Also, i would GREATLY appreciate if there is yet another method to do what i want (e.g. load and display an image) in a faster way. To be honest i am creating an app here and i compare it with the speed of others that are written in native code (or even .NET) and mine is much slower. It's hard to accept that i cannot do with Java what others are doing with c or .net, By the way: i have also tried caching the compatible image to the disk, but this is not faster: an image of 300dpi takes more time to read from a file. Another question comes in mind here: is there a format (like tif or jpg) in which i can save an image and then read-it back and still be 'compatible' without another conversion? I tried saving it as a .bmp but the size of it (30MB) makes it much slower to read... Thank you for your advice, Costas [Message sent by forum member 'csterg' (csterg)] http://forums.java.net/jive/thread.jspa?messageID=349536 =========================================================================== 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".
