Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 3397454
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 18, 20262026-05-18T04:31:50+00:00 2026-05-18T04:31:50+00:00

I am uploading some image files using servelt. I want to resize the images.

  • 0

I am uploading some image files using servelt. I want to resize the images. I converts the source to BufferedImage using below lines.

InputStream imageStream = item.getInputStream();

BufferedImage imageBuffer = ImageIO.read(imageStream);

Then i resize the image and write in a location. But, all of the output files size is 0.

I am using the following code to resize the image.

AffineTransform at = new AffineTransform();
if(sx != 0)
    at.scale( sx , sx );
AffineTransformOp ato = new AffineTransformOp(at, AffineTransformOp.TYPE_BILINEAR);
uploadImage = ato.filter(uploadImage, null); //uploadImage == BufferedImage

Is there any good way to convert inputstream to bufferedImage without damaging the image?
I am sure that the image is getting uploaded. But, after the conversion to BufferedImage, the file damaged.

I am uploading by submitting a form to doPost() method. The below line gives me the InputStream from a list item.

InputStream imageStream = item.getInputStream();

And, i am writing it by

ImageIO.write(image, "jpg", new File(path + ".jpg"));

Update

java.awt.image.ImagingOpException: Unable to transform src image
at java.awt.image.AffineTransformOp.filter(Unknown Source)
at com.pricar.servlet.imageupload.ImageUploadServlet.reSize(ImageUploadServlet.java:100)
at com.pricar.servlet.imageupload.ImageUploadServlet.doPost(ImageUploadServlet.java:74)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:641)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:722)
at org.mortbay.jetty.servlet.ServletHolder.handle(ServletHolder.java:511)
at org.mortbay.jetty.servlet.ServletHandler.handle(ServletHandler.java:390)
at org.mortbay.jetty.security.SecurityHandler.handle(SecurityHandler.java:216)
at org.mortbay.jetty.servlet.SessionHandler.handle(SessionHandler.java:182)
at org.mortbay.jetty.handler.ContextHandler.handle(ContextHandler.java:765)
at org.mortbay.jetty.webapp.WebAppContext.handle(WebAppContext.java:418)
at org.mortbay.jetty.handler.ContextHandlerCollection.handle(ContextHandlerCollection.java:230)
at org.mortbay.jetty.handler.HandlerCollection.handle(HandlerCollection.java:114)
at org.mortbay.jetty.handler.HandlerWrapper.handle(HandlerWrapper.java:152)
at org.mortbay.jetty.Server.handle(Server.java:326)
at org.mortbay.jetty.HttpConnection.handleRequest(HttpConnection.java:542)
at org.mortbay.jetty.HttpConnection$RequestHandler.content(HttpConnection.java:943)
at org.mortbay.jetty.HttpParser.parseNext(HttpParser.java:756)
at org.mortbay.jetty.HttpParser.parseAvailable(HttpParser.java:218)
at org.mortbay.jetty.HttpConnection.handle(HttpConnection.java:404)
at org.mortbay.io.nio.SelectChannelEndPoint.run(SelectChannelEndPoint.java:410)
at org.mortbay.thread.QueuedThreadPool$PoolThread.run(QueuedThreadPool.java:582)

Any suggesstions or link woulb be appreciative!!!

Thanks!

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-18T04:31:51+00:00Added an answer on May 18, 2026 at 4:31 am

    The reason your code isn’t working is in

    uploadImage = ato.filter(uploadImage, null); //uploadImage == BufferedImage
    

    Your destination image is null.

    You have to create a new BufferedImage to put the scaled version into, like this:

    BufferedImage dstImage = new BufferedImage(width, height, BufferedImage.TYPE_INT_RGB);
    ato.filter(uploadImage, dstImage);
    

    Then, save the dstImage (using ImageIO.write).

    Edit:

    An easier way to scale down the image would be to just draw it into the dstImage at the right size:

    int dstWidth = 100;
    int dstHeight = 100;
    InputStream imageStream = item.getInputStream();
    BufferedImage srcImage = ImageIO.read(imageStream);
    if (srcImage == null) { System.err.println("NO SOURCE IMAGE!"); }
    BufferedImage dstImage = new BufferedImage(dstWidth, dstHeight,
        BufferedImage.TYPE_INT_RGB);
    dstImage.getGraphics().drawImage(
        srcImage, 0, 0, dstWidth, dstHeight, null);
    ImageIO.write(dstImage, "jpg", new File(path + ".jpg"));
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am using PHP/MySQL to handle the image uploading. I want all images that
I am uploading some images using plupload and adding those images to div container.And
I'm uploading some files. Below is part of the script for the upload (I'm
I'm using django-storages with amazon S3, and uploading image files with: models.ImageField(upload_to=img=%Y-%m-%d, max_length=256, blank=True,
I want to get some files from my computer (text, video, images) and I'd
I am uploading files using HttpWebRequest to an ASP.Net MVC application but, for some
I am using this code http://stunningco.de/2010/04/25/uploading-files-to-http-server-using-post-android-sdk/ to send an image to my web server
I am currently looking in to some file uploading using Java Server Faces. I've
I have some command-line ruby scripts for things like pre-processing text files before uploading
I am using tiny mce with a script I built for uploading some content

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.