C#
  Home arrow C# arrow Page 4 - Lossless Image Converting in C#
ASP Free Forums 
.NET  
ASP  
ASP Code  
ASP.NET  
ASP.NET Code  
BrainDump  
C#  
Code Examples  
Database  
Database Code  
IIS  
Microsoft Access  
MS SQL Server  
Visual Basic.NET  
Windows Scripting  
Windows Security  
XML  
ASP Web Hosting  
ASP.NET Web Hosting 
Mobile Linux 
App Generation ROI 
Windows Web Hosting
 
IBM® developerWorks 
Sun Developer Network 
Weekly Newsletter
 
Developer Updates  
Free Website Content 
 RSS  Articles
 RSS  Forums
 RSS  All Feeds
Write For Us Get Paid 
Request Media Kit
Contact Us 
Site Map 
Privacy Policy 
Support 
 USERNAME
 
 PASSWORD
 
 
  >>> SIGN UP!  
  Lost Password? 
C#

Lossless Image Converting in C#
By: Barzan "Tony" Antal
  • Search For More Articles!
  • Disclaimer
  • Author Terms
  • Rating: 5 stars5 stars5 stars5 stars5 stars / 4
    2008-02-13

    Table of Contents:
  • Lossless Image Converting in C#
  • First Things First
  • The Real Thing
  • Taking a Break

  • Rate this Article: Poor Best 
      ADD THIS ARTICLE TO:
      Del.ici.ous Digg
      Blink Simpy
      Google Spurl
      Y! MyWeb Furl
    Email Me Similar Content When Posted
    Add Developer Shed Article Feed To Your Site
    Email Article To Friend
    Print Version Of Article
    PDF Version Of Article
     
     
    ADVERTISEMENT


    Lossless Image Converting in C# - Taking a Break


    (Page 4 of 4 )

    Finally we have created the groundwork for our Lightweight Image Manipulation application. At this stage our little utility software is able to convert images. Certainly we cannot say that's some outstanding function, but still, the purpose of this article was to learn how to design, implement, and code these kinds of applications.

    The attached source code for the first part, because the resizing is going to be covered in the next segment, can be found below. It is a ZIP archive and you should just extract the whole archive to your chosen destination. As I already mentioned, the project was developed with Visual Studio 2005.

    I also want to point out the fact that if you play around with the image conversion application we've just finished programming, you may notice that if you convert to GIF extension, then the conversion by no means will be lossless. The destination image becomes very pixelated and a bit blurry. Some of the color palettes become misplaced. I am going to attach two example images so you can catch my drift easier.

    (The image on left is in original JPG format, the one on right is converted to GIF.)

    "Why does that happen?" In short, it happens because of color quantization. Regardless of the encoder settings (such as high quality) we choose, our image quality gets destroyed due to the loss conversion. A better term for color quantization is color reduction. However, the de facto standard usage in DSP and computing is quantization.

    By its very nature, the GIF extension format doesn't allow more than 256 palette entries. And an image always has a particular number of colors in each of its palettes. Therefore, quantization is required for each GIF image file, especially when converting 16-, 24- or higher bit images. It is necessary to do a quantization algorithm when resizing any image to GIF format. With other formats, this isn't an issue.

    So as you had noticed, the "default" quantization algorithm of .NET's GDI+ is optimized for speed and not quality. It is a web development environment and it makes sense that speed is more important than quality, especially back in those days when we were struggling with dial-up connections. To improve our GIF conversion, we'll stick with an independent and different quantization algorithm, but that's for the next part!

    Until next time, keep coding and remember - Perfect practice makes perfect!


    DISCLAIMER: The content provided in this article is not warranted or guaranteed by Developer Shed, Inc. The content provided is intended for entertainment and/or educational purposes in order to introduce to the reader key ideas, concepts, and/or product reviews. As such it is incumbent upon the reader to employ real-world tactics for security and implementation of best practices. We are not liable for any negative consequences that may result from implementing any information covered in our articles or tutorials. If this is a hardware review, it is not recommended to open and/or modify your hardware.

       · Thanks for reading the first part of this 2-part series. Don't hesitate to leave...
       · The quality of the result image is poor... with graphics software (gimp, photoshop)...
     

    C# ARTICLES

    - C# and XML
    - Pointers and Arrays in C#
    - C# 3.0 Extension Methods
    - Overloading Operators in C#
    - Iterators and Nullable Types
    - Patterns and Iterators in C#
    - C# Exceptions
    - Methods in C#
    - Delegates and Events in C#
    - Advanced C#
    - Working with Regular Expressions in C#
    - Sending Simple E-Mail in C#
    - Building C# Comparable Objects: IComparable ...
    - Color Transformation Applications in C# GDI+...
    - Performing Color Transformation Operations i...





    © 2003-2008 by Developer Shed. All rights reserved. DS Cluster 2 hosted by Hostway
    Stay green...Green IT