Writting GIF images

I'm trying to make a program that converts images from one format to another ( BMP, GIF, JPG), and I got stuck at writting GIF's.
I noticed that this essue appeared before. Any solutions? JAI doesn't seem to support writting GIF's (something about patenting the encoding algorithm).

Hi,
did you look at the new Image I/O Framework?
http://java.sun.com/j2se/1.4.1/docs/guide/imageio/index.html
- Puce

Similar Messages

  • How can i write the image in gif or jpeg format??

    how can i write the image in gif or jpeg format??

    thx someone else help me in another topic

  • Loss transparency in an animated GIF image when resizing

    Hi Friends,
    I have to write a program to resize GIF, JPEG , and PNG images. I wrote and it works but when i resize a GIF file it loses its transparency and give a black color for transparent area.
    I used a GifDecoder found at www.fmsware.com/stuff/GifDecoder.java
    and a gif encoder found at jmge.net/java/gifenc/Gif89a090b.zip.
    i don't know where the problem is .
    i have some small problems in here.
    How can i preserve the transparency of GIF image?
    How can i set a transparent color in Graphic2D object? smtimes it may help me. or error may be in the encoder.
    Help me guys.
    Thanks and regards,
    Manjula

    Java comes with gif encoder/decoders.
    Gifs are indexed images. This means that, for example, each pixel is an 8 bit value that is used to look up the correct 24 bit value in the index table. Gifs handle transparency by allowing one particular pixel value to be nominated as transparent.
    If you just rescale the image then you will likely cause pixels with the magic "transparent" value to change their value and become normal pixels. Alternately pixels that are not transparent may have their values changed such that they are transparent.
    Possibly the easyist solution to to force the image into a full RGBA image. Scale this then perform post processing on the image. I.e convert it back into an indexed image, looking at the values of the alpha channel (prior to making it indexed and if they are high enough then modify the corresponding pixel in the indexed image to have the magic transparent value. Then use Metadata passed to your Image writer to indicate which value is transparent.
    matfud

  • How to decoding and encoding PNG and GIF images?

    I could decode and encode JPEG images using following create functions which are in com.sun.image.codec.jpeg package.
    JPEGImageDecoder decoder = JPEGCodec          .createJPEGDecoder(inputStream);
    JPEGImageEncoder encoder = JPEGCodec                    .createJPEGEncoder(outputStream);
    But I dont know required package and functions to decode and encode PNG and GIF images. Please help me.

    Is the API that hard to follow?
    ImageIO.read( file/stream/url)
    ImageIO.write( image, format (e.g. PNG, GIF(1), JPEG), file/stream what have you)
    1) Not sure if Java supports GIF saving, it might if you install JAI, or Java 6.

  • Writing gif image to a word document

    I want to write a gif image to a Microsoft Word 2000 file. I used several ways with IO Streams but nothing worked right for me. I know that its quite easy with javax.imageio.* package of j2sdk1.4.0 to write images to files. But the problem is that my hosting plan might not upgrade to the new version of jdk and will not be able to support j2sdk1.4.0 for few months. If somebody can send the code it will be very highly appreciated for 1.3 or earlier jdks.
    Please help urgent.
    Thanks
    Muhammad Salman
    [email protected]

    it's not necessarily to a word file, but if you download the Java Advanced Imaging APIs from JavaSoft, they will work in JDK 1.3 to write out gif files. These optional APIs were replaced by the JDK 1.4 ones.
    But to take it one step further, you can do JNI and use COM Activation to load the gif you just wrote out into a word.

  • How JPG or GIF Image open in MIDP?

    How my j2me application can support jpg or gif image format. I have tested png file in midp 1.0 and its not support other than png format( im not sure about midp 2.0 does it support or not). I have seen lot of mobiles those support gif and jpg file formats. Does j2me applications on those mobile can support other image formats?
    Plus it is possible that i can develop my own decoder for jpg or gif format. I know it possible, but im talking related to its processing power consumption. Or is there any third party api exist to support jpg or gif file format on midp. Please r

    Here is the code snap that read image from a URL.. I have tested this code on localhost & two different pc on lan in emulator.. but not in actuall mobile... but i hope it will work...
    Image image = null ;
    DataInputStream httpInput = null ;
    DataOutputStream httpOutput = null ;
    HttpConnection httpCon = null ;
    String url = "http://localhost:8080/images/picture.png"
    try
    httpCon = (HttpConnection)Connector.open(url);
    int bufferSize = 512 ;
         byte byteInput[] = new byte[bufferSize] ;
         ByteArrayOutputStream imageBuffer = new ByteArrayOutputStream(1024*50);
         httpInput = new DataInputStream( httpCon.openInputStream() );
                   System.out.println("Http-Input Connecting Establish Successfully");
                   httpOutput = new DataOutputStream( httpCon.openOutputStream() );
                   System.out.println("Http-Output Establish Successfully");
    int size = 0 ;
    // read all image data ....
         while ( ( size = httpInput.read( byteInput , 0 , bufferSize ) ) != -1 )
                        imageBuffer.write( byteInput , 0 , size ) ;
    // get byte from buffer stream
              byte byteImage[] = imageBuffer.toByteArray();
                   System.out.println("read byte " + byteImage.length );
         // convert byte to image ...
         image = Image.createImage( byteImage , 0 , byteImage.length );
         return image ;
         //return null ;
    catch( IOException e )
                   System.out.println("\nUnable to Perform Image IO Operation with Host");
         return null ;
    ....................................

  • Error in downloading .gif image

    hi frndz
    I am writing an application which downloads the image from server
    for .jpeg, .jpg, .png its working fine but for .gif images it gives me the error: ArrayIndexOutOfBoundException
    Code for downloading Image is:
    ContentConnection connection = (ContentConnection) Connector.open(url);
    DataInputStream iStrm = connection.openDataInputStream();
    // two methods are used to download IMAGE
    // (I) If length available , (II) If length not available
    int length = (int) connection.getLength();
    // (Method I :) ContentConnection includes a length method
    if (length != -1)
    imageData = new byte[length];
    iStrm.readFully(imageData);
    // (Method II :) If Length not available...
    else
    ByteArrayOutputStream bStrm = new ByteArrayOutputStream();
    int ch;
    while ((ch = iStrm.read()) != -1) bStrm.write(ch);
    imageData = bStrm.toByteArray();
    if (bStrm != null) bStrm.close();
    // Create the image from the byte array
    img = Image.createImage(imageData, 0, imageData.length-1);
    When I print Image length its zero and also imageData length is zero
    is there any other method to download .gif images
    thanks
    alpesh

    the problem is not in displaying image
    and by the way i am testing this on N70
    problem is in downloading
    i.e. image length is zero as well asif I dont consider image length the downloaded bytes are zero
    alpesh

  • How do I write an image to a file

    I have a java application where I use paint() to draw on a JPanel
    Is there a way I can save this image (such as a gif or jpg) so that it can be displayed later on within an HTML page?
    I am sure this must be achievable but I dont know how
    Simon

    I'm working on this same problem. Its starting to look like the only ways to do it are to either:
    1) use Java Advanced Imaging (JIA) to encode and write the image file
    or
    2) use java 1.4's IOImage API
    Is my assumption correct, that these are the only ways to do it? My company is on 1.3.1 and can't move up to 1.4 right now. We don't want to use JAI b/c of the extra memory it consumes. Anyone know of a way to do it in jdk 1.3.1 standard edition? I've looked through all the docs on this site that I could find and nothing talks about this.

  • How to resize GIF images

    Hi
    I used acme.jar to wirte gif images to a local disk . i worked fine , but iam facing problem in resizing these images , when i resize these images i get black background color in tat images .. can any body help me regarding this.....
    thumbImage = scaleToSize(imageWidth, imageHeight, thumbImage);
    Graphics2D graphics2D = thumbImage.createGraphics();
    graphics2D.setRenderingHint(RenderingHints.KEY_INTERPOLATION,
         RenderingHints.VALUE_INTERPOLATION_BILINEAR);
         graphics2D.drawImage(image,0,0,     thumbWidth,thumbHeight,null);
    out = new BufferedOutputStream(new FileOutputStream(newFilePath));
    GifEncoder gife = new GifEncoder(image,out);     
    gife.encode();
    this is my code .....

    Following is my code:
    public final String dealFile(ActionMapping mapping,ActionForm form,
                   HttpServletRequest request) throws FileNotFoundException, IOException{
              GroupForm gForm = (GroupForm) form;
              ActionMessages errors = new ActionMessages();
              // retrieve the file representation
              FormFile file = gForm.getPictFile();
              if (file == null) {
                   errors.add("FileNeeded", new ActionMessage("error.photo.filenull"));
                   saveErrors(request, errors);
                   return "failure";
              // has the maximum length been exceeded?
              Boolean maxLengthExceeded = (Boolean) request
                        .getAttribute(MultipartRequestHandler.ATTRIBUTE_MAX_LENGTH_EXCEEDED);
              if ((maxLengthExceeded != null) && (maxLengthExceeded.booleanValue())) {
                   errors.add("maxLengthExceeded", new ActionMessage(
                             "error.photo.length"));
                   saveErrors(request, errors);
                   return "failure";
              // retrieve the file name
              String fileName = file.getFileName();
              // judge file type
              String fileType = fileName.substring(fileName.lastIndexOf(".") + 1);
              if (!(fileType.equalsIgnoreCase("jpg")
                        || fileType.equalsIgnoreCase("jpeg")
                        || fileType.equalsIgnoreCase("gif") || fileType
                        .equalsIgnoreCase("png"))) {
                   errors.add("NotPict", new ActionMessage("error.photo.wrongformat"));
                   saveErrors(request, errors);
                   return "failure";
              Date date = new Date();
              Random r = new Random(date.getTime());
              // ������������
              String newFileName = request.getSession().getId() + r.nextInt(10000)
                        + "." + fileType;
              String filePath = null;
              String newFilePath = null;
              // the directory to upload to
              String uploadDir = servlet.getServletContext()
                        .getRealPath("/resources")
                        + "/groupphoto/" + DateUtil.asShortString(date)+"/";
              // prepare directory if not exists
              File dirPath = new File(uploadDir);
              if (!dirPath.exists()) {
                   dirPath.mkdirs();
              // retrieve the file data
              InputStream stream = file.getInputStream();
              // write the file to the file specified
              OutputStream bos = new FileOutputStream(uploadDir + newFileName);
              int bytesRead = 0;
              byte[] buffer = new byte[8192];
              while ((bytesRead = stream.read(buffer, 0, 8192)) != -1) {
                   bos.write(buffer, 0, bytesRead);
              bos.close();
              buffer = null;
              filePath = dirPath.getAbsolutePath() + Constants.FILE_SEP
                        + newFileName;
              File _file = new File(uploadDir + newFileName);
              Image src = ImageIO.read(_file); // ����Image����
              int width = src.getWidth(null); // ����������
              int height = src.getHeight(null);// ����������
              // convert the picture to picture within 100x100 and save to a file with
              // prefix
              // 100x100_ for later listing purpose.
              newFilePath = dirPath.getAbsolutePath() +Constants.FILE_SEP
                        + "100x100_" + newFileName;
              int newWidth = 0;
              int newHeight = 0;
              int bigger = width <= height ? height : width;
              if (bigger > 100) {
                   if (width >= height) {
                        newWidth = 100;
                        newHeight = height * 100 / width;
                   } else {
                        newHeight = 100;
                        newWidth = width * 100 / height;
                   ImageUtil.convert(filePath, newFilePath, newWidth, newHeight);
              // close the stream
              stream.close();
              _file = null;
              src = null;
              dirPath = null;
              String url = request.getContextPath() + "/resources" + "/groupphoto/"
              + DateUtil.asShortString(date)+"/"+ "100x100_" + newFileName;
              return url;          
         }

  • To place text or gif image on another gif image

    We have requirement to write some content on top of a GIF image. Is it possible to write a text or embed a GIF image on top of a GIF image? We are using jdk1.3.1.
    The final image should be a gif or jpeg image.
    Using graphics2d drawstring method, we can write a text on a image but graphics2d can be placed on the canvas for displaying purpose but how to convert this graphics2d to bufferedimage so that we can save as gif or jpeg image.

    Uh oh, another consultancy firm not supplying the correct output to a client. Who woulda thunk?

  • Resize gif-image from file

    How to make the following: open the GIF-file, reduce a gif-image, write a gif-image back in the GIF-file? It is necessary to use only Java2D.
    Thanks.

    You could use the JAI.
    Any way you do it you're going to have to do an Affine Transform. You can do it in just the JDK or use JAI.

  • Error while loading a logo .gif image to the banner

    Hi all,
    I'm running Portalea on NT platform and I receive the following error, trying to load a gif image as a logo to the banner (this is in spanish but I hope you can understand it):
    Wed, 27 Dec 2000 07:03:25 GMT
    ORA-06510: PL/SQL: excepcisn definida por el usuario no tratada
    ORA-06512: en "PORTAL30.WWDOC_DOCU_BRI_TRG", lmnea 60
    ORA-06510: PL/SQL: excepcisn definida por el usuario no tratada
    ORA-04088: error durante la ejecucisn del disparador 'PORTAL30.WWDOC_DOCU_BRI_TRG'
    DAD name: portal30
    PROCEDURE : PORTAL30.wwptl_banner.savecustom
    URL : http://ORACLE1:80/pls/portal30/PORTAL30.wwptl_banner.savecustom
    PARAMETERS :
    ===========
    ENVIRONMENT:
    ============
    PLSQL_GATEWAY=WebDb
    GATEWAY_IVERSION=2
    SERVER_SOFTWARE=Apache/1.3.12 (Win32) ApacheJServ/1.1 mod_ssl/2.6.4 OpenSSL/0.9.5a mod_perl/1.22
    GATEWAY_INTERFACE=CGI/1.1
    SERVER_PORT=80
    SERVER_NAME=ORACLE1
    REQUEST_METHOD=POST
    QUERY_STRING=
    PATH_INFO=/pls/portal30/PORTAL30.wwptl_banner.savecustom
    SCRIPT_NAME=/pls
    REMOTE_HOST=
    REMOTE_ADDR=192.168.100.224
    SERVER_PROTOCOL=HTTP/1.1
    REQUEST_PROTOCOL=HTTP
    REMOTE_USER=
    HTTP_CONTENT_LENGTH=6443
    HTTP_CONTENT_TYPE=multipart/form-data; boundary=---------------------------7d02753210f0280
    HTTP_USER_AGENT=Mozilla/4.0 (compatible; MSIE 5.0; Windows NT; DigExt)
    HTTP_HOST=oracle1
    HTTP_ACCEPT=application/vnd.ms-excel, application/msword, application/vnd.ms-powerpoint, image/gif, image/x-xbitmap, image/jpeg, image/pjpeg, application/x-comet, */*
    HTTP_ACCEPT_ENCODING=gzip, deflate
    HTTP_ACCEPT_LANGUAGE=es
    HTTP_ACCEPT_CHARSET=
    HTTP_COOKIE=portal30=AB515A5F55262E576590647AC04D98A8EF1D5A6F56D19ECCD710BDB4A08D2354903C0CA288FDE0C9283E116C71C00B1B3821CEAB7A24979CFF326F4979143EE1FD147BC097C2AD7705313C93DAB32D8 4A6CF71C26B267CC0B2FEA03B385A2E84; portal30_sso=7452540140821A6010973F5CAC7E7D17C7498F309E15C228015C1C0546A702F5AFDE500B69BDCB8DE5C29DD726FC8DEEE85A1DC979ECC7B8A6A16CADEF1DAB0C0ACEC11897D5B99B1033884D61307BEA7AE581C 8AB988C8CBBBDCE6174BA01F6
    Authorization=
    HTTP_IF_MODIFIED_SINCE=
    null

    Hi,
    No errors was found in the installation log. I'm looking in the WWDOC_DOCUMENT$ table and found records that make references to my previous tries to upload the logo image. In order to make others tries, how can I delete this information? Are references to this files in any other table?.
    I'm looking over the solution provide by Laurent Baresse, refering to the NLS_LANGUAJE problem ... (Thanks Laurent).
    Best regards
    <BLOCKQUOTE><font size="1" face="Verdana, Arial">quote:</font><HR>Originally posted by Karthika Siva ([email protected]):
    Fernando,
    Are you able to upload any documents into a content area? Please look at your installation log file (install.log) for any errors that may have occured during the installation of the product. Also make sure that the tablespace containing the WWDOC_DOCUMENT$ table is not full.
    Karthika<HR></BLOCKQUOTE>
    null

  • Animated Gif Image does not render correctly on screen

    I have added animated gif image to the scene it does not render correctely.it shakes on the screen. plz give me any suggestion
    i use following code
    Image logo= new Image(getClass().getResourceAsStream("images/image.gif"));
    logoLabel.setGraphic(new ImageView(logo));

    Hello user,
    I think gif are rendered smoothly.
    Are you sure you are not making many object of same images everytime?
    Thanks.
    Narayan

  • Animated gif image

    Hi
    I like to create an animated gif image from a given set of images with java. I like to do this with the given set of java api as I do not want to use a commercial graphics library. Can anyone provide me with a sample example.
    Thanks

    Hi
    I like to resize a gif image. Currently i am using the following code but the resized image is not smooth.
    public BufferedImage resizeImage(BufferedImage img, int newW, int newH)
              int w = img.getWidth();
              int h = img.getHeight();
              BufferedImage dimg = new BufferedImage(newW, newH, img.getType());
              Graphics2D g = dimg.createGraphics();
              g.setRenderingHint(RenderingHints.KEY_INTERPOLATION, RenderingHints.VALUE_INTERPOLATION_BILINEAR);
              g.drawImage(img, 0, 0, newW, newH, 0, 0, w, h, null);
              g.dispose();
              return dimg;
    Is there a way to resize a gif image in a smooth way as the example given in the gif4j library
    Thanks

  • Animated GIF image gets distorted while playing.

    Hi,
    I have some animated gif images which I need to show in a jLabel and a jTextPane. But some of these images are getting distorted while playing in the two components, though these images are playing properly in Internet Explorer. I am using the methods insertIcon() of jTextPane and setIcon() of jLabel to add or set the gif images in the two components. Can you please suggest any suitable idea of how I can get rid of this distortion? Thanks in advance.

    In the code below is a self contained JComponent that paints a series of BufferedImages as an animation. You can pause the animation, and you specify the delay. It also has two static methods for loading all the frames from a File or a URL.
    Feel free to add functionality to it, like the ability to display text or manipulate the animation. You may wan't the class to extend JLabel instead of JComponent. Just explore around with the painting. If you have any questions, then feel free to post.
    The downside to working with an array of BufferedImages, though, is that they consume more memory then a single Toolkit gif image.
    import javax.swing.JComponent;
    import java.awt.image.BufferedImage;
    import java.awt.Graphics;
    import javax.imageio.ImageIO;
    import javax.imageio.ImageReader;
    import javax.imageio.stream.ImageInputStream;
    public class JAnimationLabel extends JComponent {
        /**The default animation delay.  100 milliseconds*/
        public static final int DEFAULT_DELAY = 100;
        private BufferedImage[] images;
        private int currentIndex;
        private int delay;
        private boolean paused;
        private boolean exited;
        private final Object lock = new Object();
        //the maximum image width and height in the image array
        private int maxWidth;
        private int maxHeight;
        public JAnimationLabel(BufferedImage[] animation) {
            if(animation == null)
                throw new NullPointerException("null animation!");
            for(BufferedImage frame : animation)
                if(frame == null)
                    throw new NullPointerException("null frame in animation!");
            images = animation;
            delay = DEFAULT_DELAY;
            paused = false;
            for(BufferedImage frame : animation) {
                maxWidth = Math.max(maxWidth,frame.getWidth());
                maxHeight = Math.max(maxHeight,frame.getHeight());
            setPreferredSize(new java.awt.Dimension(maxWidth,maxHeight));
        //This method is called when a component is connected to a native
        //resource.  It is an indication that we can now start painting.
        public void addNotify() {
            super.addNotify();
            //Make anonymous thread run animation loop.  Alternative
            //would be to make the AnimationLabel class extend Runnable,
            //but this would allow innapropriate use.
            exited = false;
            Thread runner = new Thread(new Runnable() {
                public void run() {
                    runAnimation();
            runner.setDaemon(true);
            runner.start();
        public void removeNotify() {
            exited = true;
            super.removeNotify();
        /**Returns the animation delay in milliseconds.*/
        public int getDelay() {return delay;}
        /**Sets the animation delay between two
         * consecutive frames in milliseconds.*/
        public void setDelay(int delay) {this.delay = delay;}
        /**Returns whether the animation is currently paused.*/
        public boolean isPaused() {
            return exited?true:paused;}
        /**Makes the animation paused or resumes the painting.*/
        public void setPaused(boolean paused) {
            synchronized(lock) {
                this.paused = paused;
                lock.notify();
        private void runAnimation() {
            while(!exited) {
                repaint();
                if(delay > 0) {
                    try{Thread.sleep(delay);}
                    catch(InterruptedException e) {
                        System.err.println("Animation Sleep interupted");
                synchronized(lock) {
                    while(paused) {
                        try{lock.wait();}
                        catch(InterruptedException e) {}
        public void paintComponent(Graphics g) {
            if(g == null) return;
            java.awt.Rectangle bounds = g.getClipBounds();
            //center image on label
            int x = (getWidth()-maxWidth)/2;
            int y = (getHeight()-maxHeight)/2;
            g.drawImage(images[currentIndex], x, y,this);
            if(bounds.x == 0 && bounds.y == 0 &&
               bounds.width == getWidth() && bounds.height == getHeight()) {
                 //increment frame for the next time around if the bounds on
                 //the graphics object represents a full repaint
                 currentIndex = (currentIndex+1)%images.length;
            }else {
                //if partial repaint then we do not need to
                //increment to the the next frame
    }

Maybe you are looking for

  • Why do receivers of my text messages get them mixed with messages I have sent them in the past?

    The hardware is an iPhone 4 on iOS 5.1.1 with a capacity of 16GB (14.0GB). Currently I have 1.8GB available memory. The phone has never been jailbroken and no external accessories have ever been attached to it. The problem: Some of the receivers of m

  • Problem with Adobe Help in Creative Cloud

    I'm using Mac OSX 10.9 but this problem has been here before that. My Adobe Help application says "No Adobe Products are currently installed." which is completely wrong. If I look at the "Local Content tab there is nothing displayed. I did have the "

  • Automatic clearing for Vendors F.13

    Dear All, I have done MR8M ie reverse for Miro document, it shows a msg that FI Documents shud be clered manually, Our client has N number of such documents So i tried to do F.13 Automatic Clearing , but a Msg says " Account was selected, but is not

  • Restriction in Search help of Product Categories

    Hi, I am working on SRM_SERVER 5.5 and I want to restrict the Product categories depending on the Organizational attribute of the user. Its search help is COM_CATEGORY_ID in the system and i didn't find any User-Exit or Enhancement to control these v

  • Error 1097 while controlling a Velmex

    I'm using a two axis Velmex setup to quickly move a probe quickly in and out of a flame. The Velmex is supposed to move the probe into the flame, let it collect data, move it out of the flame, then repeat this process at a slightly more advanced posi