Hello,

I have a method that creates a BufferedImage from a byte[]. It is a gray-scale 
image, and each pixels in the image is represent by a single byte range from 0 
to 255. here is the method:

public BufferedImage produceRenderedImage(byte[] dataBuffer, int width, int 
height)
{
        DataBuffer dBuffer = new DataBufferByte(dataBuffer, width * height);
        WritableRaster wr  = 
Raster.createInterleavedRaster(dBuffer,width,height,width,1,new int[]{0},null);
        ColorSpace cs = ColorSpace.getInstance(ColorSpace.CS_GRAY);
    ColorModel cm = new ComponentColorModel(cs,false, false, 
Transparency.OPAQUE, DataBuffer.TYPE_BYTE);
    BufferedImage bi = new BufferedImage(cm, wr, false, null);
        
  return bi;
}

Now this method got call several time in the while loop where the while loop 
get the byte[] array of the raw image from the server. My question is that is 
there a way that i can optimize this so that it uses less "new" operator 
because it allocates space. the only changes in the above method during the 
while loop is the byte[] dataBuffer. of course the WritableRaster change as 
well since it uses byte[] dataBuffer to create the WritableRaster.

Thanks

Francis
[Message sent by forum member 'cohodetector' (cohodetector)]

http://forums.java.net/jive/thread.jspa?messageID=288912

===========================================================================
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".

Reply via email to