hzinox
asked on
Problem to display WritableRaster
Hi all,
Can anyone help me out with WritableRaster? How can I display a WritableRaster? I have accessed each pixel RGB values and compare each of them to a series of RGB values (which represents cluster centers). After accessing and comparing, the RGB value of pixels which satisfied a distance condition are changed into WHITE pixels. After all pixels in the original image had been evaluated and modified, I want to display the modified image.
I have problem with the last task. Any help is much appreciated.
Can anyone help me out with WritableRaster? How can I display a WritableRaster? I have accessed each pixel RGB values and compare each of them to a series of RGB values (which represents cluster centers). After accessing and comparing, the RGB value of pixels which satisfied a distance condition are changed into WHITE pixels. After all pixels in the original image had been evaluated and modified, I want to display the modified image.
I have problem with the last task. Any help is much appreciated.
Could be more convenient to do
http://java.sun.com/j2se/1.5.0/docs/api/java/awt/image/BufferedImage.html#setData(java.awt.image.Raster)
http://java.sun.com/j2se/1.5.0/docs/api/java/awt/image/BufferedImage.html#setData(java.awt.image.Raster)
ASKER
Hi CEHJ,
Actually I am using BufferedImage. Below is my code snippet
inputImage = new BufferedImage(w, h, BufferedImage.TYPE_INT_ARG B);
Graphics2D graphic = inputImage.createGraphics( );
graphic.drawImage(image, 0, 0, this);
outputImage = new BufferedImage(w, h, BufferedImage.TYPE_INT_ARG B);
WritableRaster input = inputImage.copyData(null);
WritableRaster output = outputImage.getRaster();
//access each pixel using r=input.getSample(i,j,0);
//comparison condition
Next is to display the outputImage???????
Thanks.
Actually I am using BufferedImage. Below is my code snippet
inputImage = new BufferedImage(w, h, BufferedImage.TYPE_INT_ARG
Graphics2D graphic = inputImage.createGraphics(
graphic.drawImage(image, 0, 0, this);
outputImage = new BufferedImage(w, h, BufferedImage.TYPE_INT_ARG
WritableRaster input = inputImage.copyData(null);
WritableRaster output = outputImage.getRaster();
//access each pixel using r=input.getSample(i,j,0);
//comparison condition
Next is to display the outputImage???????
Thanks.
Try
outputImage.setData(input) ;
// now draw it
outputImage.setData(input)
// now draw it
ASKER
Hi,
It does draws but the image drawn is the original image. Is it possible that I did not draw the image where it supposed to be drawn onto? I have an ImagePanel class to display modified image of type Image and ImageIcon..I do not faced any problem in displaying them. The ImagePanel class as below
public ImagePanel() {}
public ImagePanel(ImageIcon image)
{
this.imageIcon = image;
this.setSize(this.getImage Height(),t his.getIma geWidth()) ;
}
public ImagePanel(Image image)
{
this(new ImageIcon(image));
}
public void paintComponent(Graphics g)
{
super.paintComponent(g);
if (imageIcon != null)
{
int height = imageIcon.getIconHeight();
int width = imageIcon.getIconWidth();
g.drawImage(this.getImage( ),0,0,this );
}
}
public void setImage(ImageIcon image)
{
this.setImage(image.getIma ge());
}
public void setImage(Image image)
{
this.imageIcon = new ImageIcon(image);
this.setSize(this.getImage Height(),t his.getIma geWidth()) ;
//repaint();
}
public int getImageHeight()
{
if (imageIcon == null)
{
return -1;
}
return imageIcon.getIconHeight();
}
public int getImageWidth()
{
if (imageIcon == null)
{
return -1;
}
return imageIcon.getIconWidth();
}
public Image getImage()
{
return this.imageIcon.getImage();
}
private ImageIcon imageIcon = null;
Any help is welcome.
Thanks.
It does draws but the image drawn is the original image. Is it possible that I did not draw the image where it supposed to be drawn onto? I have an ImagePanel class to display modified image of type Image and ImageIcon..I do not faced any problem in displaying them. The ImagePanel class as below
public ImagePanel() {}
public ImagePanel(ImageIcon image)
{
this.imageIcon = image;
this.setSize(this.getImage
}
public ImagePanel(Image image)
{
this(new ImageIcon(image));
}
public void paintComponent(Graphics g)
{
super.paintComponent(g);
if (imageIcon != null)
{
int height = imageIcon.getIconHeight();
int width = imageIcon.getIconWidth();
g.drawImage(this.getImage(
}
}
public void setImage(ImageIcon image)
{
this.setImage(image.getIma
}
public void setImage(Image image)
{
this.imageIcon = new ImageIcon(image);
this.setSize(this.getImage
//repaint();
}
public int getImageHeight()
{
if (imageIcon == null)
{
return -1;
}
return imageIcon.getIconHeight();
}
public int getImageWidth()
{
if (imageIcon == null)
{
return -1;
}
return imageIcon.getIconWidth();
}
public Image getImage()
{
return this.imageIcon.getImage();
}
private ImageIcon imageIcon = null;
Any help is welcome.
Thanks.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
http://java.sun.com/j2se/1.5.0/docs/api/java/awt/image/BufferedImage.html#BufferedImage(java.awt.image.ColorModel, java.awt.image.WritableRas