Win a copy of Functional Reactive Programming this week in the Other Languages forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Image Operations

 
S Kada
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have an applet where i get an image the form of byte array .I use the createImage() of awt toolkit to create an image using the byte array .The image loads properly in applet and now i change the image using filters and convert the modified image into a byte array using the following code

/****
private byte[] convertImage(Image img)
{

try
{
int[] pix = new int[img.getWidth(null) * img.getHeight(null)];
PixelGrabber pg = new PixelGrabber(img, 0, 0, img.getWidth(null), img.getHeight(null), pix, 0, img.getWidth(null));
pg.grabPixels();

byte[] pixels = new byte[img.getWidth(null) * img.getHeight(null)];

for (int j = 0; j < pix.length; j++)
{
pixels[j] = new Integer(pix[j]).byteValue();
}
System.out.println("pixels.length = " + pixels.length);
return pixels;
}
catch (InterruptedException e)
{
e.printStackTrace();
}
return null;
}
****/

I send this byte array over to a servlet and write it to a file using file outputstream. The file is created at the location but i am not able to see the modified picture when i open the file in IE or any other editor.

Please suggest what to do ?
 
Ulf Dittmer
Rancher
Posts: 42968
73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Welcome to JavaRanch.

An array of bytes does not make an image, and writing them into a file will not produce something that most image viewers can handle. Which file format are you using to store those bytes?
 
S Kada
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Ulf Dittmer:
Welcome to JavaRanch.

An array of bytes does not make an image, and writing them into a file will not produce something that most image viewers can handle. Which file format are you using to store those bytes?



I use the following code to create the image

Toolkit toolkit = Toolkit.getDefaultToolkit();
Image image = toolkit.createImage(imageData);

imageData is an array of bytes which i get from the database and pass this to the function I mentioned. I use jpeg format to store the files.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic