Blurry JPGs when using FileUpload 1.2.1

classic Classic list List threaded Threaded
8 messages Options
Reply | Threaded
Open this post in threaded view
|

Blurry JPGs when using FileUpload 1.2.1

Bob Carpenter
Hi,

Using FileUpload 1.2.1 with Struts the image quality of my JPGs are blurry.
I've had this problem for a couple years, but was hoping that v1.2.1 would
solve the problem.

You can view the before and after images here:

  http://www.customerfeedbackllc.com/dev/receipt_before_upload.jpg
  http://www.customerfeedbackllc.com/dev/receipt_after_upload.jpg

Here is the code from my Struts Action class that does the work:

  String uploadFilePath = form.getUploadFilePath();
  InputStream is = uploadFile.getInputStream();  // uploadFile is a FormFile
  BufferedImage bufiIn = ImageIO.read(is);

  // bufiIn is stored in a custom object (TransferImage, which extends
Canvas and is Serializable) - here are the essential steps
  int[] imgPix = (int[])pix;
  int width = bufiIn.getWidth();
  int height = bufiIn.getHeight();

  BufferedImage bufiOut = new BufferedImage(width, height,
BufferedImage.TYPE_INT_BGR);
  image.setRGB(0, 0, width, height, imgPix, 0, width);

  // Write the bufi to a tmp file for viewing
  ImageIO.write(bufiOut, "jpg", new
File("c:\\tmp\\receipt_after_upload.jpg"));

The receipt_before_upload.jpg comes from a camera phone. Usually, images
coming from scanners are not as blurry.

Can you suggest any way to reduce the blurriness?

Thanks,

--BobC


---------------------------------------------------------------------
To unsubscribe, e-mail: [hidden email]
For additional commands, e-mail: [hidden email]

Reply | Threaded
Open this post in threaded view
|

RE: Blurry JPGs when using FileUpload 1.2.1

Bob Carpenter
I'm original poster - slight correction:

  WRONG:      image.setRGB(0, 0, width, height, imgPix, 0, width);

  CORRECT:    bufiOut.setRGB(0, 0, width, height, imgPix, 0, width);

--BobC



---------------------------------------------------------------------
To unsubscribe, e-mail: [hidden email]
For additional commands, e-mail: [hidden email]

Reply | Threaded
Open this post in threaded view
|

Re: Blurry JPGs when using FileUpload 1.2.1

Rory Winston
In reply to this post by Bob Carpenter
Bob

I would seriously doubt that this is in any way related to FileUpload.
Surely FileUpload just transfers binary files from a to b?

Bob Carpenter wrote:

> Hi,
>
> Using FileUpload 1.2.1 with Struts the image quality of my JPGs are blurry.
> I've had this problem for a couple years, but was hoping that v1.2.1 would
> solve the problem.
>
> You can view the before and after images here:
>
>   http://www.customerfeedbackllc.com/dev/receipt_before_upload.jpg
>   http://www.customerfeedbackllc.com/dev/receipt_after_upload.jpg
>
> Here is the code from my Struts Action class that does the work:
>
>   String uploadFilePath = form.getUploadFilePath();
>   InputStream is = uploadFile.getInputStream();  // uploadFile is a FormFile
>   BufferedImage bufiIn = ImageIO.read(is);
>
>   // bufiIn is stored in a custom object (TransferImage, which extends
> Canvas and is Serializable) - here are the essential steps
>   int[] imgPix = (int[])pix;
>   int width = bufiIn.getWidth();
>   int height = bufiIn.getHeight();
>
>   BufferedImage bufiOut = new BufferedImage(width, height,
> BufferedImage.TYPE_INT_BGR);
>   image.setRGB(0, 0, width, height, imgPix, 0, width);
>
>   // Write the bufi to a tmp file for viewing
>   ImageIO.write(bufiOut, "jpg", new
> File("c:\\tmp\\receipt_after_upload.jpg"));
>
> The receipt_before_upload.jpg comes from a camera phone. Usually, images
> coming from scanners are not as blurry.
>
> Can you suggest any way to reduce the blurriness?
>
> Thanks,
>
> --BobC
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: [hidden email]
> For additional commands, e-mail: [hidden email]
>
>
>
>
>  


---------------------------------------------------------------------
To unsubscribe, e-mail: [hidden email]
For additional commands, e-mail: [hidden email]

Reply | Threaded
Open this post in threaded view
|

Re: Blurry JPGs when using FileUpload 1.2.1

Emmanuel Bourg-3
In reply to this post by Bob Carpenter
You should write the uploaded image directly to the disk, you reduce its
quality every time your read and write it with ImageIO.

Emmanuel Bourg


Bob Carpenter a écrit :

> Hi,
>
> Using FileUpload 1.2.1 with Struts the image quality of my JPGs are blurry.
> I've had this problem for a couple years, but was hoping that v1.2.1 would
> solve the problem.
>
> You can view the before and after images here:
>
>   http://www.customerfeedbackllc.com/dev/receipt_before_upload.jpg
>   http://www.customerfeedbackllc.com/dev/receipt_after_upload.jpg
>
> Here is the code from my Struts Action class that does the work:
>
>   String uploadFilePath = form.getUploadFilePath();
>   InputStream is = uploadFile.getInputStream();  // uploadFile is a FormFile
>   BufferedImage bufiIn = ImageIO.read(is);
>
>   // bufiIn is stored in a custom object (TransferImage, which extends
> Canvas and is Serializable) - here are the essential steps
>   int[] imgPix = (int[])pix;
>   int width = bufiIn.getWidth();
>   int height = bufiIn.getHeight();
>
>   BufferedImage bufiOut = new BufferedImage(width, height,
> BufferedImage.TYPE_INT_BGR);
>   image.setRGB(0, 0, width, height, imgPix, 0, width);
>
>   // Write the bufi to a tmp file for viewing
>   ImageIO.write(bufiOut, "jpg", new
> File("c:\\tmp\\receipt_after_upload.jpg"));
>
> The receipt_before_upload.jpg comes from a camera phone. Usually, images
> coming from scanners are not as blurry.
>
> Can you suggest any way to reduce the blurriness?
>
> Thanks,
>
> --BobC
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: [hidden email]
> For additional commands, e-mail: [hidden email]
>

---------------------------------------------------------------------
To unsubscribe, e-mail: [hidden email]
For additional commands, e-mail: [hidden email]

Reply | Threaded
Open this post in threaded view
|

RE: Blurry JPGs when using FileUpload 1.2.1

Bob Carpenter
I didn't know that ImageIO reduces quality with each pass. ImageIO is used
at least twice for each file because it gets stored as a BLOB and is served
to clients by saving to disk then reading back in with ImageIO.

Thanks for the clue - I'll start looking down that path.

--BobC


-----Original Message-----
From: Emmanuel Bourg [mailto:[hidden email]]
Sent: Friday, June 13, 2008 2:18 PM
To: Commons Users List
Subject: Re: Blurry JPGs when using FileUpload 1.2.1


You should write the uploaded image directly to the disk, you reduce its
quality every time your read and write it with ImageIO.

Emmanuel Bourg


Bob Carpenter a écrit :
> Hi,
>
> Using FileUpload 1.2.1 with Struts the image quality of my JPGs are
blurry.

> I've had this problem for a couple years, but was hoping that v1.2.1 would
> solve the problem.
>
> You can view the before and after images here:
>
>   http://www.customerfeedbackllc.com/dev/receipt_before_upload.jpg
>   http://www.customerfeedbackllc.com/dev/receipt_after_upload.jpg
>
> Here is the code from my Struts Action class that does the work:
>
>   String uploadFilePath = form.getUploadFilePath();
>   InputStream is = uploadFile.getInputStream();  // uploadFile is a
FormFile

>   BufferedImage bufiIn = ImageIO.read(is);
>
>   // bufiIn is stored in a custom object (TransferImage, which extends
> Canvas and is Serializable) - here are the essential steps
>   int[] imgPix = (int[])pix;
>   int width = bufiIn.getWidth();
>   int height = bufiIn.getHeight();
>
>   BufferedImage bufiOut = new BufferedImage(width, height,
> BufferedImage.TYPE_INT_BGR);
>   image.setRGB(0, 0, width, height, imgPix, 0, width);
>
>   // Write the bufi to a tmp file for viewing
>   ImageIO.write(bufiOut, "jpg", new
> File("c:\\tmp\\receipt_after_upload.jpg"));
>
> The receipt_before_upload.jpg comes from a camera phone. Usually, images
> coming from scanners are not as blurry.
>
> Can you suggest any way to reduce the blurriness?
>
> Thanks,
>
> --BobC
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: [hidden email]
> For additional commands, e-mail: [hidden email]
>

---------------------------------------------------------------------
To unsubscribe, e-mail: [hidden email]
For additional commands, e-mail: [hidden email]


---------------------------------------------------------------------
To unsubscribe, e-mail: [hidden email]
For additional commands, e-mail: [hidden email]

Reply | Threaded
Open this post in threaded view
|

Re: Blurry JPGs when using FileUpload 1.2.1

James Carman
We greatly improved performance by just writing image files out to
disk and letting a webserver take care of streaming them back.
Perhaps that might help in your situation?

On Fri, Jun 13, 2008 at 8:07 PM, Bob Carpenter <[hidden email]> wrote:

> I didn't know that ImageIO reduces quality with each pass. ImageIO is used
> at least twice for each file because it gets stored as a BLOB and is served
> to clients by saving to disk then reading back in with ImageIO.
>
> Thanks for the clue - I'll start looking down that path.
>
> --BobC
>
>
> -----Original Message-----
> From: Emmanuel Bourg [mailto:[hidden email]]
> Sent: Friday, June 13, 2008 2:18 PM
> To: Commons Users List
> Subject: Re: Blurry JPGs when using FileUpload 1.2.1
>
>
> You should write the uploaded image directly to the disk, you reduce its
> quality every time your read and write it with ImageIO.
>
> Emmanuel Bourg
>
>
> Bob Carpenter a écrit :
>> Hi,
>>
>> Using FileUpload 1.2.1 with Struts the image quality of my JPGs are
> blurry.
>> I've had this problem for a couple years, but was hoping that v1.2.1 would
>> solve the problem.
>>
>> You can view the before and after images here:
>>
>>   http://www.customerfeedbackllc.com/dev/receipt_before_upload.jpg
>>   http://www.customerfeedbackllc.com/dev/receipt_after_upload.jpg
>>
>> Here is the code from my Struts Action class that does the work:
>>
>>   String uploadFilePath = form.getUploadFilePath();
>>   InputStream is = uploadFile.getInputStream();  // uploadFile is a
> FormFile
>>   BufferedImage bufiIn = ImageIO.read(is);
>>
>>   // bufiIn is stored in a custom object (TransferImage, which extends
>> Canvas and is Serializable) - here are the essential steps
>>   int[] imgPix = (int[])pix;
>>   int width = bufiIn.getWidth();
>>   int height = bufiIn.getHeight();
>>
>>   BufferedImage bufiOut = new BufferedImage(width, height,
>> BufferedImage.TYPE_INT_BGR);
>>   image.setRGB(0, 0, width, height, imgPix, 0, width);
>>
>>   // Write the bufi to a tmp file for viewing
>>   ImageIO.write(bufiOut, "jpg", new
>> File("c:\\tmp\\receipt_after_upload.jpg"));
>>
>> The receipt_before_upload.jpg comes from a camera phone. Usually, images
>> coming from scanners are not as blurry.
>>
>> Can you suggest any way to reduce the blurriness?
>>
>> Thanks,
>>
>> --BobC
>>
>>
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: [hidden email]
>> For additional commands, e-mail: [hidden email]
>>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: [hidden email]
> For additional commands, e-mail: [hidden email]
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: [hidden email]
> For additional commands, e-mail: [hidden email]
>
>

---------------------------------------------------------------------
To unsubscribe, e-mail: [hidden email]
For additional commands, e-mail: [hidden email]

Reply | Threaded
Open this post in threaded view
|

Re: Blurry JPGs when using FileUpload 1.2.1

bgiles
In reply to this post by Bob Carpenter
This is a good trick when you're standardizing image size and quality
based on project requirements.  On my last project we knew the images
were going into 2x3" panels in a PDF document and could reduce
everything to around 20k.

Bob Carpenter wrote:

> I didn't know that ImageIO reduces quality with each pass. ImageIO is used
> at least twice for each file because it gets stored as a BLOB and is served
> to clients by saving to disk then reading back in with ImageIO.
>
> Thanks for the clue - I'll start looking down that path.
>
> --BobC
>
>
> -----Original Message-----
> From: Emmanuel Bourg [mailto:[hidden email]]
> Sent: Friday, June 13, 2008 2:18 PM
> To: Commons Users List
> Subject: Re: Blurry JPGs when using FileUpload 1.2.1
>
>
> You should write the uploaded image directly to the disk, you reduce its
> quality every time your read and write it with ImageIO.
>
> Emmanuel Bourg
>
>
> Bob Carpenter a écrit :
>  
>> Hi,
>>
>> Using FileUpload 1.2.1 with Struts the image quality of my JPGs are
>>    
> blurry.
>  
>> I've had this problem for a couple years, but was hoping that v1.2.1 would
>> solve the problem.
>>
>> You can view the before and after images here:
>>
>>   http://www.customerfeedbackllc.com/dev/receipt_before_upload.jpg
>>   http://www.customerfeedbackllc.com/dev/receipt_after_upload.jpg
>>
>> Here is the code from my Struts Action class that does the work:
>>
>>   String uploadFilePath = form.getUploadFilePath();
>>   InputStream is = uploadFile.getInputStream();  // uploadFile is a
>>    
> FormFile
>  
>>   BufferedImage bufiIn = ImageIO.read(is);
>>
>>   // bufiIn is stored in a custom object (TransferImage, which extends
>> Canvas and is Serializable) - here are the essential steps
>>   int[] imgPix = (int[])pix;
>>   int width = bufiIn.getWidth();
>>   int height = bufiIn.getHeight();
>>
>>   BufferedImage bufiOut = new BufferedImage(width, height,
>> BufferedImage.TYPE_INT_BGR);
>>   image.setRGB(0, 0, width, height, imgPix, 0, width);
>>
>>   // Write the bufi to a tmp file for viewing
>>   ImageIO.write(bufiOut, "jpg", new
>> File("c:\\tmp\\receipt_after_upload.jpg"));
>>
>> The receipt_before_upload.jpg comes from a camera phone. Usually, images
>> coming from scanners are not as blurry.
>>
>> Can you suggest any way to reduce the blurriness?
>>
>> Thanks,
>>
>> --BobC
>>
>>
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: [hidden email]
>> For additional commands, e-mail: [hidden email]
>>
>>    
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: [hidden email]
> For additional commands, e-mail: [hidden email]
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: [hidden email]
> For additional commands, e-mail: [hidden email]
>
>  


---------------------------------------------------------------------
To unsubscribe, e-mail: [hidden email]
For additional commands, e-mail: [hidden email]

Reply | Threaded
Open this post in threaded view
|

Re: Blurry JPGs when using FileUpload 1.2.1

Christopher Schultz-2
In reply to this post by Bob Carpenter
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Bob,

Bob Carpenter wrote:
| I didn't know that ImageIO reduces quality with each pass.

It's not so much ImageIO as JPEG in general. JPEG is lossy compression
which means that each time you encode a JPEG image, you lose some detail
because of the cosine coefficients that are dropped to perform the
compression.

This is amplified by the probability that you are reading a JPEG at a
certain level of detail (say "90%" JPEG detail) and writing it out at
another level (say, "50%" detail).

| ImageIO is used
| at least twice for each file because it gets stored as a BLOB and is
served
| to clients by saving to disk then reading back in with ImageIO.

You should try to avoid JPEG interpretation of your image files unless
you actually need to do image processing. You ought to be able to read
and write raw bytes a lot of the time. That will significantly improve
the performance of your application, too!

- -chris
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.9 (MingW32)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org

iEYEARECAAYFAkhWcEsACgkQ9CaO5/Lv0PBGGQCgqR4s7UrUA/r9YmEEsT1C1EGF
AuEAoJ0xlGRzm4ZFU/WotbYjyOkCnzUY
=QtV5
-----END PGP SIGNATURE-----

---------------------------------------------------------------------
To unsubscribe, e-mail: [hidden email]
For additional commands, e-mail: [hidden email]