This week's giveaway is in the Android forum.
We're giving away four copies of Android Security Essentials Live Lessons and have Godfrey Nolan on-line!
See this thread for details.
The moose likes Other JSE/JEE APIs and the fly likes Image Operations Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Java » Other JSE/JEE APIs
Bookmark "Image Operations" Watch "Image Operations" New topic
Author

Image Operations

S Kada
Greenhorn

Joined: Jun 01, 2006
Posts: 4
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
Marshal

Joined: Mar 22, 2005
Posts: 41124
    
  45
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?


Ping & DNS - my free Android networking tools app
S Kada
Greenhorn

Joined: Jun 01, 2006
Posts: 4
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.
 
jQuery in Action, 2nd edition
 
subject: Image Operations
 
Similar Threads
java.lang.IllegalArgumentException: im == null!
getting problem in creating an image from int array
Java image and byte[] for J2ME and J2SE
painting an image
single dimension array to multi dimension