I have this jpg image I need to show in a applet. But I can�t let this image get download to the user computer.
So what I am thinking is
All images are shown using pixels and RGB values. Say I have a 40 X40 image (actually my image is 400 X 300) then this has 1600 pixels each has RGB values so all together 1600 X3 values. If I can get these values and save in an int array and draw my image using these values, it is like rendering my image from the java code. I only know this is possible. But I don�t know how to do it
This has to be possible with JAI API but I am looking a solution using normal J2SE 1.5
I'm a bit unclear on what you're trying to do. Applets can display JPEGs directly, but you don't want to do that - can you elaborate why not? Downloading the pixels as values (for which you'd need a servlet or something to serve them to the applet) is kind of the same as downloading them in the shape of an JPEG, isn't it? If you still want to go the route of downloading pixel values, you don't need JAI to draw them - AWT will suffice.
Ping & DNS - updated with new look and Ping home screen widget
Joined: Nov 15, 2004
Thanks a lot. i wont be downloading the values. it will be in the code let say as byte array Lets say I have a 500X400 JPG image with size about 25 to 30 KB
500X400=200000 pixels So it is 600000 values so if we save it in a java file what will the size will be 10 to 15 KB right so it will download faster and you have told that �you don't need JAI to draw them - AWT will suffice� then can you tell me how to draw the image if I have all the RGB values of all the pixels
and you will have to tell me how to get the RGB values from the image as well
Thank fro the help [ August 11, 2005: Message edited by: Sameera Abeysinghe ]
Joined: Mar 22, 2005
In your paint method, you would use something like
g.setColor(new Color(r, g, b)); g.drawLine(x, y, x, y);
where g is the Graphics object, and r/g/b are the color values of the pixel at postion x/y.
Why do you need the pixels from the image? I thought you said you wanted to store them directly in an array? Loading an image into an applet is done using Applet.loadImage(), getting pixels from that Image is a bit tricky and I don't remember the details. I think it involved various interfaces like ImageConsumer, ImageProducer and ImageObserver - googling for it may give you a better answer. [ August 11, 2005: Message edited by: Ulf Dittmer ]
Lets say I have a 500X400 JPG image with size about 25 to 30 KB 500X400=200000 pixels So it is 600000 values so if we save it in a java file what will the size will be 10 to 15 KB right so it will download faster
I don't think so. Storing 600000 bytes in a binary file would give you a file that's 585k. You'll have to think much harder to beat the compression in a JPG or GIF file.
i manege to do what i wonted get the pixcel values of the image and recreate the image useing the values but it did not happen as i expected after saveing the values in a txt file the size of the file in 1.5 MB so dont need to tell it is not working