• 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
  • Ron McLeod
  • Paul Clapham
  • Tim Cooke
  • Devaka Cooray
Sheriffs:
  • Liutauras Vilda
  • paul wheaton
  • Rob Spoor
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • Piet Souris
  • Mikalai Zaikin
Bartenders:
  • Carey Brown
  • Roland Mueller

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.
 
Hey cool! They got a blimp! But I have a tiny ad:
We need your help - Coderanch server fundraiser
https://coderanch.com/wiki/782867/Coderanch-server-fundraiser
reply
    Bookmark Topic Watch Topic
  • New Topic