[java] int array -> image

Started by
1 comment, last by Seyedof 23 years, 1 month ago
Hi i''m a c++ programmer, recently i''ve learned some java and just started porting some of my old demo effects to java applets. In this case i ported my Plasma demo to a japplet but i have problems for converting an array of ints to an image. i use something like : MyImage = createImage ( new MemoryImageSource (.... it works but damn slow and i think it wastes the system resources coz in each thread loop (where i update the array of ints containing plasma pixels) i must call createImage ( new .... which creates a new image and doing this 25 time per second is a HELL ! The problem is clear, i wanna update the int array of pixels in each thread loop and then convert this array to an image to be displayed on screen, what is the most efficient way to do this conversion or instead getting direct access to the image piexl data for modification? thanks --MFC (The Matrix Foundation Crew)
--MFC (The Matrix Foundation Crew)
Advertisement
I think you should first create your BufferedImage object and then use the getRaster() method which gives you a reference to the WritableRaster (or maybe it is the getData() to have just a Raster I can''t remember) of your image, which is actually the array containing info about each pixel of the image.
I used this last year in a school project for compressing/decompressing images and I found this quite easy to alter pixel state quickly. Indeed, this way you can modify an image content even while the GUI is currently drawing it to the screen.
If you''re using java1.2.2 or older, AFAIK you should create a MemoryImageSource object at initialization time, do memorySource.setAnimated(true); and then do Image img = createImage(memorySource); so this is done just once.
Then each frame you should call memorySource.newPixels(); which each time constructs a new Image object from the pixels you have in your array.

Something like that.
- Fovster

This topic is closed to new replies.

Advertisement