• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Image Operations

 
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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 ?
 
Rancher
Posts: 43081
77
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
reply
    Bookmark Topic Watch Topic
  • New Topic