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;          
     }

Similar Messages

  • How to resize multiple images?

    I am newbie to RH and would like to know if there is a method /shortcut by which I can resize multiple images?
    Specifically to my project: I have close to 50 tables containing various images and their descriptions. When I insert these images into RH, the original image size is inserted and these images are of various sizes.
    I know how to resize multiple images in Word but not in RH and hence, reaching to higher powers
    I am using RH 9
    Appreciate all your help!

    Hi There, Well the best option is to resize each image individually but if you feel that you can select all images together and the  resize them all at once I am sure that you would like to give a read to this post from forums which talks about this job
    http://forums.adobe.com/thread/466933

  • How to resize display image item?

    How to resize an image in display image item not in column?
    I find a way to resize it in column which similar to this way
    decode(nvl(dbms_lob.getlength(PLAYER_PIC),0),0,null,
    '<img style="border: 4px solid #CCC; -moz-border-radius: 4px; -webkit-border-radius:
    4px;" '||
    'src="'||
    apex_util.get_blob_file_src('P5_PLAYER_PIC',ROWID)||
    '" height="75" width="75" alt="Player Image" title="Player Image" />')
    detail_img
    but when I try to implement it to display image item which I returned the image from the column, I cant resize it this way, or may be I used wrong syntax, can you please help me finding way to resize it with steps?

    I guess it is because of some carriage returns in your dynamic img tag that is being generated may be not, so make sure there are no breaks half-way through he attributes of the img tag.
    decode(nvl(dbms_lob.getlength(PLAYER_PIC),0),0,null, '<img style="border: 4px solid #CCC; -moz-border-radius: 4px; -webkit-border-radius: 4px;" '|| 'src="'|| apex_util.get_blob_file_src('P5_PLAYER_PIC',ROWID)|| '" height="75" width="75" alt="Player Image" title="Player Image" />')  detail_imgand also inspect the element/img to see if the code is rendered correctly
    Thanks

  • Guys, i want to ask on how to resize the images into 1200 pixels wide?

    Guys, i want to ask on how to resize the images into 1200 pixels wide, how to do it? and what are the step by steps on doing that? thank you!!!

    See this link: http://forums.adobe.com/docs/DOC-3691

  • 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 ;
    ....................................

  • RESIZING GIF IMAGES WITHOUT LOSING ANIMATION

    Is it possible to resize a Gif image without losing animation?  I tried but unfortunately lost the animation. I use CS3 Extended.  Thanks

    No, I don't think so. for that, you'd probably have to import your animation using the Video to Layers option, resize, then rebuild the animation and export it.
    Mylenium

  • 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.

  • How to resize and image in iPhoto for a favicon on website

    I am trying to add "favicon" to my website and it says it says the image needs to be 16x16 or 32x32 and no larger than 100KB how do i resize the image i want to use to fir these guidlines?

    you go into iphoto then you click on the photo u want to re-size down the bottom there should be 4 icon there should be one saying edit click on that then up the top there are three icon click on the one that says quick fix the click on crop next to the word constrain there is a long bar click on that scroll down it will say custom click on that then put in the size you want the photo to be then u are good to go

  • How to set gif image as wallpaper in Nokia s60v3 m...

    Hi, I am using N79 and i want set gif image as wallpaper.when i am trying to set a gif image as wallpaper no animation is coming on standby screen
    How to set gif wallpaper on standby screen with animation

    Not sure but you may have to install this application
    http://www.mobidhoom.com/anim-sprite-lite-v233s60v3/
    Try and give your feedback..
    --------------------------------------------------​--------------------------------------------------​--------------------------------------------------​--If you find this helpful, pl. hit the White Star in Green Box...

  • How to Print GIF image in XML RTF Report

    Hi All,
    I have one requirement like to print the GIF image in Oracle Report.
    The report is an XML Report.
    The image file stored in database, the table is fnd_attached_docs_form_vl.
    select distinct file_name from fnd_attached_docs_form_vl
    Front end Navigation ----->
    view -----> Attachments
    Now i need to get the image from there and print it report.
    Can you pls help me.
    Regards
    Venu

    Hi,
    I didn't tried that scenario as my report is not a Non-XML Report.
    And my report is XML Report.
    Regards
    Venu

  • How to insert GIF images in Blogs

    I am able to insert GIF images in to blogs... but its not playing .. only static..
    Any help..
    Thanks in advance..
    Regards,
    Mahesh

    Yes.. Its working perfect. (Sorry Jyoti sir for copy-paste)

  • How to resize photoshop image without changing canvas size?

    When i had the older versions of photoshop i would change the image size and it would enlarge on my canvas for me to rearrange. Lately i realized on CC when i increase image size so does my canvas size. Is there anyway to prevent my canvas size from increasing too?

    I am having what appears to be this same issue.    I am using PS CC.  
    hello @ c.pfaffenbichler
    I resized my image in image> image size.  
    Details:
    I am not a ps expert but woefully self taught.  However through much trial and error I have in my experience over the years, achieved some comfortability with the image size dialog box as well as the canvas size dialog box.  SOME comfortability lol.  That is, I feel that I understand what is going on most of the time and when flummoxed have studied adobe literature or read hundreds of posts here and elsewhere to gain additional knowledge which many times resolves the issue.  I like digging and finding the answers.
    In this case, my digging is done dug a giant hole and I am exhausted and found nuthin'.
    I feel like I am going nutso.
    In my mind,
    1.  There is the image I am working on
    2.  There is the canvas the image is sitting on
    My expectation and previous experience is that I can change the Image size by going to Image > image size and this change does not affect the canvas size.
    My expectation and previous experience is that I can go to Image >canvas size and change the canvas size and this does not affect the image size.
    I could also use the Transform to resize the image which also, would not in my expectation, change the canvas size.
    In the beginning of my workflow on this particular collage I did not have this issue,  so that leads me to believe I did or am doing something to cause this rather than it being some kind of bug.    But what do I know.
    I thank you in advance for your assistance.

  • How to resize large images without losing quality

    Hello I have an image that I am trying to use as an email. Right now it is 2108 pixels. And for an email it should be 600 px. I created this image in illustrator as vectors and type.
    Whenever I go into image size and i change it to be 600 pixels it gets extremely blurry. I have also tried converting this to a smart object... doesnt work. How do I resize my large image to be smaller without losing quality???

    here is an example sceenshot of the opening dialog (.ai opened directly in Photoshop)
    your illustrator vector should be rastered sharp at 100% actual Pixels in Photoshop
    that is where you want to evaluate sharpness in Photoshop...
    then File> Save for Web & Devices (and drag that saved file icon into an open web browser)
    still no joy, embed your saved image here using the forum's camera icon...

  • How to resize an image without squashing it?

    I am trying to add image to mug template ,so when I resize it get squashed how I resolve this
    thanks

    Hold the shift key down while resizing, and check that the percentages are the same in the top bar. (The numbers on the far right in these screen shots)
    It doesn't matter what the numbers are, as long as they match each other.
    WRONG:
    CORRECT:

  • Anyone how to resize an image using imagereader and imagereadparam?

    I want to use imagereaderparam to process the image.
    MY code is as follow:
    ImageReader reader = _editor.getImageReader();
         try
         if (reader != null)
                   int w = reader.getWidth(0);
                   int h = reader.getHeight(0);
                   ImageReadParam param = reader.getDefaultReadParam();
                   //param.setDestination(reader.read(0));
                   Dimension d = new Dimension(my_width, my_height);
                   param.setSourceRenderSize(d);
                   BufferedImage bi = reader.read(0, param);
         } catch (Exception e)
              e.printStackTrace();
    This code just not work , and get an exception
    java.lang.UnsupportedOperationException: Can't set source render size!
    anyone know how to do that ?
    coz i dont want to use getScaledImage...

    Hi,
    Are you just trying to produce a BufferedImage at a smaller size? May I ask why you don't want to use getScaledInstance? I agree with you not to use it. It is slow. Just wondering what your reasons are. If all you need is to take one image and make it a different size, try this:
    BufferedImage src = ...
    int scale = 0.5f;
    int w = (int)(src.getWidth(null) * scale);
    int h = (int)(src.getHeight(null) * scale);
    // could use TYPE_INT_RGB if there's no alpha in your image
    BufferedImage dest = new BufferedImage(w, h, BufferedImage.TYPE_INT_ARGB);
    Graphics g = dest.getGraphics();
    g.drawImage(src, 0, 0, w, h, null);
    d.dispose();How does that work for you? It should be pretty quick.
    Shannon Hickey (Swing Team)

Maybe you are looking for