Newsgroup: it.comp.java
Titolo: How to save a file in Gif Or Jpeg Format made by Image Producer like "Memory Image Source"

Dear Friend,
Hi! There. I am making a project in Java for my college and I am facing
a  small problem which I am sure that you would be able to help me out.
I am making an image from data using an image producer liek Memory Image
Source. The problem is that although the image is being displayed
correctly I want to know the procedure with the help of which I could
save the given image in GIF or JPEG format. For that do I have to learn
there respective algos or is there any other simpler method  provided in
Java. For more clarity I am providing a small program code (application)
below which displays an image using "memoryImagesource()"
   import java.awt.*;
   import java.awt.image.*;
   public class im extends Frame{
      static FileDialog fd;
      static Image img;
      public static void main(String args[])
      {
         im f=new im();
         f.show();
         f.resize(400,400);
         int w = 200;
         int h = 200;
         int pixels[] = new int[w * h];
         int i = 0;
         for(int y=0; y<h; y++) {
            for(int x=0; x<w; x++) {
               int r = (x^y)&0xff;
               int g = (x*2^y*2)&0xff;
               int b = (x*4^y*4)&0xff;
               pixels[i++] = (255 << 24) | (r << 16) | (g << 8) | b;
            }
         }
         img = f.getToolkit().createImage(new MemoryImageSource(w, h,
pixels, 0, w));
      }
      public void paint(Graphics g)
      {
         g.drawImage(img,0,0,this);
      }
   }
Thanking you in anticipation and hoping to get a quick response
                         \\\\/////
                         / ^   ^ \
 ____                   ( (o) (o) )                       ____
( __ )---------------oOOO---(_)-----OOOo-----------------( __ )
 |  |                                                     |  |
 |  |                   Vikram Kumar                      |  |
 |  |                                                     |  |
 |  |      mailto:
vik...@employees.org
                    |  |
 |  |                                                     |  |
 |  |      
http://www.employees.org/~vikram
               |  |
 |  |      
http://members.tripod.com/~Coolviki
            |  |
 |  |      
http://i.am/coolviki
                           |  |
 |  |      
http://vikram.pyar.com
                         |  |
 |__|                                                     |__|
(____)---------------------------------------------------(____)

 save the given image in GIF or JPEG format.
Try 
www.acme.com
, there's a GIF encoder.
Ciao,
	Stefano

below which displays an image using "memoryImagesource()"
Sun has released a package explicitily for images I/O; here is a part
of the documentation:
"Jimi is a class library for managing images.  Its primary function is
in image I/O, however it has a considerable range of supporting
features for image viewing, managing large or very-large images
independently of physical memory, extension for support new types of
imaging, and more.  Jimi's range of supported formats include, to
varying degreees, GIF(no compressed encoding) JPEG, TIFF, PNG, PICT,
Photoshop, BMP, Targa, ICO, CUR, Sunraster, XBM, XPM, PCX, DCX"
It's approx. a 3.5Mb download at Sun's site.
Bye AzriEl
-----------------------
Azr...@freemail.it

import com.sun.image.codec.jpeg.* ;
bimge[bicont] is a buffered image
OutputStream out = null;
try {
out = new FileOutputStream("temp.jpg");
JPEGImageEncoder encoder = JPEGCodec.createJPEGEncoder(out);
JPEGEncodeParam param = encoder.getDefaultJPEGEncodeParam(bimge[bicont]);
param.setQuality(0.75f,true);
encoder.encode( bimge[bicont],param);
out.close();
} catch (IOException e) {}
--
Vladimiro Severino
webm...@ennaonline.com
`\\|||/
   (@@)
ooO_(_)_Ooo______________________________________________________
_____|_____|_____|_____|_____|_____|_____|_____|_____|_____|_____|____
___|____|_____|_____|_____|_____|_____|_____|_____|_____|_____|_____|_
_____| Se ami il Web, non puoi  fare a  meno di EnnaOnLine!!! ________|___
_____|_____|_____|_____|_____|_____|_____|_____|_____|_____|_____|____
___|____|___ 
http://www.ennaonline.com
 |_____|_____|_____|_____|_____|_
_|______|____|_____|_____|_____|_____|_____|_____|_____|_____|_____|___|_
AzriEl <Azriel@_NOSPAM_freemail.it> wrote in message
37ef5cf...@news.tin.it...
