473,395 Members | 1,456 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,395 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 3046
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: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

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.