C#
  Home arrow C# arrow Page 2 - Lossless Image Converting in C#
Iron Speed
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 
Dedicated Servers 
Actuate Whitepapers 
VeriSign Whitepapers 
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

    At the virtual BlackBerry Technical Seminar 2008, you can ask your development questions directly of Research In Motion® (RIM) experts, and take advantage of learning opportunities designed uniquely for BlackBerry solution developers. Register Today!

    Lossless Image Converting in C# - First Things First


    (Page 2 of 4 )

    The first thing is the third habit of highly effective people as described in Stephen Covey's book. It has been said that it applies to every area of our lives. That's true and here we can also include programming. For that reason we fire up our Visual Studio and start a new Windows Application in C#. Then we add the following namespaces:

    using System;

    using System.Drawing;

    using System.Collections;

    using System.ComponentModel;

    using System.Windows.Forms;

    using System.Data;

    using System.Drawing.Imaging;

    We design and architect our form so it looks the fanciest with the components we require. That is, a PictureBox for a preview thumbnail, a few Buttons (Select, Quit, Convert), a ComboBox where we include the available extensions for conversion, an OpenFileDialog and SaveFileDialog, and finally we add the appropriate label(s).

    Check out the way my form looks. Please pay attention to how I have additionally noted the name of each component with the arrow. This way you can follow along during this tutorial while I showcase my code snippets as well as my explanations when I'm referring to particular components. So please design your form appropriately.

    (Form Design - Screenshot)

    Now that we have architected our form we can continue. Although the above screenshot doesn't show the OpenFileDialog and SaveFileDialog, we shouldn't forget to add those components. I have named them SelectPicture and saveFileDialog1, respectively. Once those are also created, let's move on!

    Here are a few additional details regarding our main form. I have named it clsMain. Its exact size is (455, 318) - (width, height). I have disabled the maximizeBox and the FormBorderStyle is set to FixedSingle. Its title is visible from my screenshot: Lightweight Image Manipulation. Now let's fasten our seat belts and speed up!

    Check out the attached code snippet. With these we jump-start our application.

    public clsMain()

    {

       InitializeComponent();

    }

    static void Main()

    {

       Application.Run(new clsMain());

    }

    private void clsMain_Load(object sender, EventArgs e)

    {

       this.lbl_extension.Hide();

       this.ComboBox1.Hide();

       this.btnConvert.Hide();

       SelectPicture.Filter = "All Image files|*.bmp; *.gif; *.jpg; *.ico; " + "*.emf; *.wmf|Bitmap Files (*.bmp; *.gif; *.jpg; " + "*.ico)|*.bmp; *.gif; *.jpg; *.ico|" + "Meta Files (*.emf; *.wmf; *.png)|*.emf; *.wmf; *.png";

    }

    Keep in mind that some of these might have been automatically generated by the Windows Form Designer, so just recheck their existence [here I'm referring to clsMain() and Main()]. As you can notice from the above block of code, we hide the components we don't need to see now until the image isn't selected (please note that we don't hide the btnSelectPicture!). We also configure the filter of SelectPicture for images.

    More C# Articles
    More By Barzan "Tony" Antal


       · 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

    - Exceptions in C#
    - Overriding versus Overloading
    - Value Types and Reference Types
    - Defining Member and Type Visibility
    - Managing Files in C#
    - Working with Windows Registry in C#
    - Lossless Image Resizing in C#
    - Lossless Image Converting in C#
    - Creating an RSS Feed with ASP.Net Written in...
    - Polymorphism in C#
    - Inheritance in C#
    - C# Events Explained
    - C# Delegates Explained
    - C# StreamReader and StreamWriter Explained
    - C# FileStream Explained





    © 2003-2008 by Developer Shed. All rights reserved. DS Cluster 5 hosted by Hostway