I am writing an application that decodes image data from a network stream and then renders it. I need two rendering modes, one for on screen rendering and one for image rendering to disk. Because the data is often raw pixels, I am currently using the code below to allow access to the pixel data directly and then copy the changed pixels to the regular BufferedImage. When the data stream has a line or rectangle encoded, I draw directly to the BufferedImage. Is there a faster/smarter way to do this? I have tried accessing the pixels stored in the DataBufferInt rather than using the pixel[] below and performance is horrendous.
Thanks in advance for any suggestions.
pixels = new int[width * height];
memImageSrc = new MemoryImageSource(width, height, colorModel, pixels, 0, width);
memImageSrc.setAnimated(true);
memImage = new BufferedImage(width, height, BufferedImage.TYPE_INT_RGB);
memGraphics = memImage.getGraphics();
pixelsSource = new MemoryImageSource(width, height, colorModel, pixels, 0, width);
pixelsSource.setAnimated(true);
rawPixelsImage = Toolkit.getDefaultToolkit().createImage(pixelsSource);