BufferedImage displays as streaky; smooth image not produced

Hi all,

I have three classes that I'm working with. One is ImageProcessor, a Class I have to process images. Another is IMAQGUI, a GUI for my IMAQ service, and the third is IMAQIceStormService.

In IMAQIceStormService, I am using ImageProcessor to create an image from a byte[] that gets sent to me, and I'm using IMAQGUI to display the image on my GUI.

All this is working fine, except the image does not display properly. I am getting the proper data, as I have compared the camera image to my streaky image, and saw that they are the same. The width, height, depth, and stride should all be correct; 1000x1000 pixels, 8 bits per pixel, and a stride of 0. I recently changed my ImageProcessor code to make some methods static, and I may have broken something.

Basically, can anyone take a look at my ImageProcessor methods, and possibly give any suggestions as to why the image is not displaying correctly?

Here is the relevant part of IMAQIceStormService:

publicvoid imageAcquired(long id, IMAQTypes.ImageDesc imageDesc,byte[] imageData,

Ice.Current current){

IMAQGUI.appendImage(ImageProcessor.createImage(imageData, imageDesc.width, imageDesc.height));

}

IMAQTypes.ImageDesc is simply the image description. It tells me the width, height, depth, and stride of the image. As you can see, I am telling IMAQGUI to appendImage based on what returns from ImageProcessor. First, here is the relevant code from IMAQGUI:

privatestatic JLabel imageViewer =new JLabel();// this gets added to the main panel in a different method

publicstaticvoid appendImage(BufferedImage image){

imageViewer.setIcon(new ImageIcon(image));

imageViewer.revalidate();

}

This just sets the icon to the new image, and revalidates the JLabel so it displays the new image.

Finally, here is the most important part. This is the relevant code from ImageProcessor:

publicstatic BufferedImage toImage(byte[] data,int w,int h){

DataBuffer buffer =new DataBufferByte(data, data.length);

WritableRaster raster = Raster.createInterleavedRaster(buffer, w, h, w,

1,newint[]{

0

} ,null);

ColorSpace cs = ColorSpace.getInstance(ColorSpace.CS_GRAY);

ColorModel cm =new ComponentColorModel(cs, false, true,

Transparency.OPAQUE, DataBuffer.TYPE_BYTE);

returnnew BufferedImage(cm, raster, false,null);

}

publicstatic BufferedImage createImage(byte[] data,int width,int height){

BufferedImage im = toImage(data, width, height);

//image = toImage(data, width, height);

BufferedImage out = createRGBImage(im);

return out;

}

publicstatic BufferedImage createRGBImage(BufferedImage in){

BufferedImage output =new BufferedImage(in.getWidth(), in.getHeight(), BufferedImage.TYPE_INT_RGB);

Graphics2D g = output.createGraphics();

g.drawRenderedImage(in,null);

g.dispose();

return output;

}

I am unsure of why ImageProcessor is creating a streaky image, especially because I know the image dimensions are correct. Is there something I am missing? Does anyone see any mistakes anywhere? Does anyone have any suggestions?

I know this is a lot of information, so thanks a lot for any help you can provide.

[4874 byte] By [Djaunla] at [2007-11-27 5:56:37]
# 1

Hi again,

I'm still unsure as to what the problem is here. I thought maybe it had something to do with the GUI container, but I saved the BufferedImage to the local filesystem using ImageIO.write(), and it looks the same.

Although no one has apparently seen any obvious problems, can someone possibly let me know if the methods are correct for what I am trying to do: convert a byte[] to a BufferedImage of RGB format?

Djaunla at 2007-7-12 16:27:33 > top of Java-index,Desktop,Core GUI APIs...
# 2
Hi all.The problem was with the capturing of the camera image and had nothing to do with my Java. I was told that the image capturing was correct, but it apparently had a small bug.Thanks for your time, and sorry that this turned out to be unrelated to Java.Dan
Djaunla at 2007-7-12 16:27:33 > top of Java-index,Desktop,Core GUI APIs...