Welcome to Dream.In.Code
Become an Expert!

Join 150,239 Programmers for FREE! Get instant access to thousands of experts, tutorials, code snippets, and more! There are 2,359 people online right now. Registration is fast and FREE... Join Now!




Lossless Image Rotating?

 
Reply to this topicStart new topic

Lossless Image Rotating?

girasquid
30 Nov, 2007 - 01:41 PM
Post #1

Barbarbar
Group Icon

Joined: 3 Oct, 2006
Posts: 1,295



Thanked: 18 times
Dream Kudos: 725
My Contributions
Hello, all.

I am currently working on a project where we have stored an image into our database - with a small and medium-sized version. Right now, I am writing code that will allow us to rotate that image, so that we can adjust it without needing to use any other tools. This is my code:
CODE

            Image smallImage;
            Image mediumImage;

            smallImage = Image.FromStream(new MemoryStream(Wrapper.Picture.GetSmallData(pictureID)));
            mediumImage = Image.FromStream(new MemoryStream(Wrapper.Picture.GetMediumData(pictureID)));

            smallImage.RotateFlip(RotateFlipType.Rotate270FlipXY);
            mediumImage.RotateFlip(RotateFlipType.Rotate270FlipXY);


            MemoryStream small = new MemoryStream();
            MemoryStream medium = new MemoryStream();

            smallImage.Save(small,ImageFormat.Jpeg);
            mediumImage.Save(medium,ImageFormat.Jpeg);

            byte[] s = small.ToArray();
            byte[] m = medium.ToArray();


And it works, except that over time it causes the pictures to lose quality.

Does anyone know of a way to implement the same functionality(rotating pictures) without loss of image quality through prolonged use?

Thanks,
Girasquid
User is offlineProfile CardPM
+Quote Post

Jayman
RE: Lossless Image Rotating?
30 Nov, 2007 - 02:16 PM
Post #2

Student of Life
Group Icon

Joined: 26 Dec, 2005
Posts: 7,319



Thanked: 66 times
Dream Kudos: 500
Expert In: Everything

My Contributions
JPEG uses a lossy compression algorithm. Meaning every time you save the image it will throw away some pixels in order to compress the file, as you have already experienced. Over time this degrades the quality of the image.

Save the image in either a TIFF, PNG or BMP format to prevent loss of image quality. These formats do not throw away information each time the file is compressed.
User is offlineProfile CardPM
+Quote Post

Fast ReplyReply to this topicStart new topic
Time is now: 1/9/09 06:21AM

Be Social

Dream.In.Code RSS Feed Dream.In.Code LinkedIn Group Follow Us On Twitter

Live Help!

Tutorials

Programming

Web Development

Reference Sheets

Code Snippets

DIC Chatroom

Bye Bye Ads

Monthly Drawing

Thumb Drive

Top Contributors

Top 10 Kudos This Month