Search - Articles
DevASP.NET for ASP.NET, VB.NET, XML and C# (C-Sharp) Developers Tuesday, March 03, 2009
Dev Articles
Search Directory
ASP.NET
VB.Net
C-Sharp
SQL Server
 

How to convert image to other extension and reduce its size in .NET 2.0.

Author: DevASP
Download Source Code : 584_image_cnverter.zip

In this simple article you will learn that how you can convert image to other extension and reduce its size.

Simply just create New Project of console application in VB.

 

Drag two text box, two radio buttons, two buttons, and two image boxes on form.

 

Import two DLLs

 

Imports System.Drawing.Imaging

Imports System.IO

 

Now just write code against these events

 

 

Private Sub m_btnOpen_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles m_btnOpen.Click

 

        Dim strFileName As String = txtinput.Text

        m_bitmap = New Bitmap(strFileName)

        m_width0 = m_pictureBox.Width

        m_height0 = m_pictureBox.Height

 

        If m_bitmap.Width > m_bitmap.Height Then

            'Keep the width

            m_pictureBox.Width = m_width0

            m_pictureBox.Height = CType((CType(m_bitmap.Height * m_width0 / m_bitmap.Width, Double)), Integer)

 

        Else

 

            'Keep the height

            m_pictureBox.Height = m_height0

            m_pictureBox.Width = CType((CType(m_bitmap.Width * m_height0 / m_bitmap.Height, Double)), Integer)

 

        End If

 

        m_pictureBox.Image = m_bitmap

 

        Me.Text = "Image Converter: " + strFileName

 

        m_btnSaveAs.Enabled = True

 

 

      

 

 

    End Sub

 

    Private Sub m_btnSaveAs_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles m_btnSaveAs.Click

        Dim strFileName As String = txtoutput.Text

        If (radio1.Checked) Then

 

            m_bitmap.Save(strFileName, ImageFormat.Jpeg)

 

        End If

 

        If (radio2.Checked) Then

 

            m_bitmap.Save(strFileName, ImageFormat.Tiff)

 

        End If

 

 

 

        m_picturebox1.Image = m_bitmap

 

        Me.Text = "Image Converter: " + strFileName

 

    End Sub

 

Private Sub fileinfo_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load

 

        Me.Text = "DevAsp"

 

        Me.BackColor = Color.LightGray

 

    End Sub

 

There are a lot of formats this article just show you from TIF to JPG and JPG to TIF only you can try by your own this is .net library for users this is in net 2.0.

 

 

Note:

 

Please select the TIF images and JPG image with right path else Application show error.

Article Comments
The article is very good . This gives a clear idea of converting images of diff types. Thanks Devasp

Posted on 7/11/2007 1:53:39 PM by amjad

   
Add Article Comment:
Name :
Email Address :
   
Comments :
 
   
<< How to convert image to other extension and reduce its size in .NET 2.0.

Disclaimer - Privacy
© 2002-2017 DevASP.net