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
 

Resize bitmap image using lowest and highest quality interpolation mode in VB.net – C#.net.

Author: Shehzad Hemani
Download Source Code : 1095_source.zip

In this simple article you will learn that how we can resize bitmap using the lowest and highest quality interpolation mode in VB.net – C#.net.

 Lowest quality interpolation mode:

This is a technique to resize the image. To resize the image with lowest quality interpolation method first we have to set a property of graphics class named InterpolationMode. This property get or set the interpolation mode of the graphics. This property takes and returns the value of enumeration interpolationmode. For lowest quality we set this property to value NearestNeighbor. After setting this property you have to change the size of the image and draw it on the form by using draw image function of graphics class. This function takes five parameters. You can read about this in one of my previous articles.

To demonstrate write the following code on Form Paint Event.

C#

private void OnPaint(object sender, PaintEventArgs e)

        {

            try

            {

                Graphics g = e.Graphics;

                Bitmap bitmap = new Bitmap("a.bmp");

                g.FillRectangle(Brushes.White, this.ClientRectangle);

                int height = bitmap.Height;

                int width = bitmap.Width;

                g.InterpolationMode = InterpolationMode.NearestNeighbor;

                g.DrawImage(bitmap, new Rectangle(15, 15, 110, 110), new Rectangle(0, 0, width, height), GraphicsUnit.Pixel);

            }

            catch (Exception EX)

            {

                MessageBox.Show(EX.Message);

            }

VB

Private Sub OnPaint(ByVal sender As ObjectByVal As PaintEventArgs)
        
Try 
            Dim 
As Graphics e.Graphics
            
Dim bitmap As Bitmap = New Bitmap("a.bmp")
            g.FillRectangle(Brushes.White, 
Me.ClientRectangle)
            
Dim height As Integer = bitmap.Height
            
Dim width As Integer = bitmap.Width
            g.InterpolationMode 
InterpolationMode.NearestNeighbor
            g.DrawImage(bitmap, 
New Rectangle(1515110110), New Rectangle(00, width, height), GraphicsUnit.Pixel)
        
Catch EX As Exception
            
MessageBox.Show(EX.Message)
        
End Try
    End Sub

This is simple code to resize image using lowest quality interpolation mode.

Highest quality interpolation mode:

This is a technique to resize the image. To resize the image with highest quality interpolation method first we have to set a property of graphics class named InterpolationMode. This property get or set the interpolation mode of the graphics. This property takes and returns the value of enumeration interpolationmode. For lowest quality we set this property to value HighQualityBicubic. After setting this property you have to change the size of the image and draw it on the form by using draw image function of graphics class. This function takes five parameters.

To demonstrate write the following code on Form Paint Event.

C#

private void OnPaint(object sender, PaintEventArgs e)

        {

            try

            {

                Graphics g = e.Graphics;

                Bitmap bitmap = new Bitmap("a.bmp");

                g.FillRectangle(Brushes.White, this.ClientRectangle);

                int height = bitmap.Height;

                int width = bitmap.Width;

                g.InterpolationMode = InterpolationMode.HighQualityBicubic;

                g.DrawImage(bitmap, new Rectangle(115, 15, 110, 110), new Rectangle(0, 0, width, height), GraphicsUnit.Pixel);

            }

            catch (Exception EX)

            {

                MessageBox.Show(EX.Message);

            }

VB

Private Sub OnPaint(ByVal sender As ObjectByVal As PaintEventArgs)
        
Try 
            Dim 
As Graphics e.Graphics
            
Dim bitmap As Bitmap = New Bitmap("a.bmp")
            g.FillRectangle(Brushes.White, 
Me.ClientRectangle)
            
Dim height As Integer = bitmap.Height
            
Dim width As Integer = bitmap.Width
            g.InterpolationMode 
InterpolationMode.HighQualityBicubic
            g.DrawImage(bitmap, 
New Rectangle(11515110110), New Rectangle(00, width, height), GraphicsUnit.Pixel)
        
Catch EX As Exception
            
MessageBox.Show(EX.Message)
        
End Try
    End Sub

This is simple code to resize image using highest quality interpolation mode.

Now write the following code on FORM LOAD event:

C#

private void Form1_Load(object sender, EventArgs e)

        {          

            this.Text = "Devasp Application";

        }

VB

Private Sub Form1_Load(ByVal sender As ObjectByVal As EventArgs)
        
Me.Text "Devasp Application"

    End Sub

This simple article tells that how we can resize bitmap image using lowest and highest quality interpolation mode in VB.net – C#.net.

   
Add Article Comment:
Name :
Email Address :
   
Comments :
 
   
<< Draw Array of images using Graphics class in VB.net – C#.net.

Disclaimer - Privacy
© 2002-2017 DevASP.net