473,321 Members | 1,669 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,321 software developers and data experts.

Is Degradation in Quality Necessary?

I'm using the following code to rotate an image (jpeg or gif), and have
discovered that there is a significant degradation in the quality of the
photo.

Just wondering if there is a way to rotate/flip a graphic in .NET *without*
data loss. If so, how? If not, why?

I understand that when *resizing* a graphic, some degradation in the
appearance will result from the loss of data. However, when it comes to
simply rotating or flipping a graphic, is it necessary that any data loss
will occur?

System.IO.FileStream fs = new System.IO.FileStream(pathToOriginal,
System.IO.FileMode.Open, System.IO.FileAccess.ReadWrite);
System.Drawing.Image imageToFlip = System.Drawing.Image.FromStream(fs);
imageToFlip.RotateFlip(System.Drawing.RotateFlipTy pe.Rotate90FlipNone);
// then either of these depending on the origina'ls format (jpeg or gif):
imageToFlip.Save(pathToOriginal, System.Drawing.Imaging.ImageFormat.Jpeg);
imageToFlip.Save(pathToOriginal, System.Drawing.Imaging.ImageFormat.Gif);

Thanks.
Nov 16 '05 #1
2 3036
Cecil Windham wrote:

I'm using the following code to rotate an image (jpeg or gif), and have
discovered that there is a significant degradation in the quality of the
photo.

Just wondering if there is a way to rotate/flip a graphic in .NET *without*
data loss. If so, how? If not, why?

I understand that when *resizing* a graphic, some degradation in the
appearance will result from the loss of data. However, when it comes to
simply rotating or flipping a graphic, is it necessary that any data loss
will occur?

System.IO.FileStream fs = new System.IO.FileStream(pathToOriginal,
System.IO.FileMode.Open, System.IO.FileAccess.ReadWrite);
System.Drawing.Image imageToFlip = System.Drawing.Image.FromStream(fs);
imageToFlip.RotateFlip(System.Drawing.RotateFlipTy pe.Rotate90FlipNone);
// then either of these depending on the origina'ls format (jpeg or gif):
imageToFlip.Save(pathToOriginal, System.Drawing.Imaging.ImageFormat.Jpeg);
imageToFlip.Save(pathToOriginal, System.Drawing.Imaging.ImageFormat.Gif);

Thanks.


As you are aware, jpeg compression is lossy. During a rotate, the image has to
be decompressed, rotated, and then recompressed. The recompression will cause
inevitable loss of quality.

I don't know the details of the compressor, but most jpeg compressors have a
quality (and other) settings to be used during compression. The default may be
to minimize size (at the expense of visual quality). Check the docs and see if
you can change to a higher quality compression.
Nov 16 '05 #2
Just to add to this response, there is a way to do a lossless rotation of a
JPEG image. A search on Google should turn up some results since it is
widely used in digital image catalogue programs.

Colin

"Julie" <ju***@nospam.com> wrote in message
news:40***************@nospam.com...
Cecil Windham wrote:

I'm using the following code to rotate an image (jpeg or gif), and have
discovered that there is a significant degradation in the quality of the
photo.

Just wondering if there is a way to rotate/flip a graphic in .NET *without* data loss. If so, how? If not, why?

I understand that when *resizing* a graphic, some degradation in the
appearance will result from the loss of data. However, when it comes to
simply rotating or flipping a graphic, is it necessary that any data loss will occur?

System.IO.FileStream fs = new System.IO.FileStream(pathToOriginal,
System.IO.FileMode.Open, System.IO.FileAccess.ReadWrite);
System.Drawing.Image imageToFlip = System.Drawing.Image.FromStream(fs);
imageToFlip.RotateFlip(System.Drawing.RotateFlipTy pe.Rotate90FlipNone);
// then either of these depending on the origina'ls format (jpeg or gif): imageToFlip.Save(pathToOriginal, System.Drawing.Imaging.ImageFormat.Jpeg); imageToFlip.Save(pathToOriginal, System.Drawing.Imaging.ImageFormat.Gif);
Thanks.
As you are aware, jpeg compression is lossy. During a rotate, the image

has to be decompressed, rotated, and then recompressed. The recompression will cause inevitable loss of quality.

I don't know the details of the compressor, but most jpeg compressors have a quality (and other) settings to be used during compression. The default may be to minimize size (at the expense of visual quality). Check the docs and see if you can change to a higher quality compression.

Nov 16 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
by: Yash | last post by:
We have an application that loads millions of records into a table. Around 10 fields in this record are date fields. We perform the insert using SQL*Loader in direct path mode. The loading takes a...
4
by: Jason Heyes | last post by:
What can I do to circumvent the performance degradation associated with dynamic allocation and small objects? Thanks.
4
by: Cecil Windham | last post by:
I'm using the following code to rotate an image (jpeg or gif), and have discovered that there is a significant degradation in the quality of the photo. Just wondering if there is a way to...
2
by: Travis | last post by:
Hi everyone, I'm using the System.Drawing.Imaging.Bitmap to retrieve and modify the metadata tags (user comments, keywords etc) of JPEGS. I was wondering if changing these tags in any way...
6
by: Michael | last post by:
I'm trying to use the Bitmap class's Save Method to save a Bitmap as a GIF. My code runs fine, and converts the image, but the quality is not anywhere close to as good. I know that GIF quality is...
15
by: WHY | last post by:
Since there's no way to create a c# method with optional, or nullable parameters. And since you can't write an overloaded web method. Is it possible to edit the WSDL in conjunction with a c#...
3
by: petermichaux | last post by:
Hi, I'm trying to do the right thing. I currently have a page that doesn't have any JavaScript and the page works. The page works with CSS on or off. Now I would like to add some JavaScript to...
8
by: berkshire | last post by:
Hi, Anyone know of a script out there that can resize images and not sacrifice image quality? I've been using phpthumb (http://phpthumb.sourceforge.net/) but when compared to an image resized...
0
by: RajaSS | last post by:
Hi, I have a windowed mode graphics application which uses OpenGL and Directx3D. Though the quality of the graphics and text I have is very good intially, once I lock and unloack my system it goes...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.