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 make a thumbnail image in VB - C #.net.

Author: Maliha Atteeq
Download Source Code : 1090_code.zip

In this simple article you will learn that how to make a thumbnail image in vb and C #.net.

 Graphics:

While playing with the graphics you must keep the following point in your mind:

You can’t draw graphics on simple load event of the form. To create graphics on the form, you must override the onpaint() function of the form.

The syntax of the onpaint() function is:

C#:

protected override void OnPaint (PaintEventArgs e)

{

}

VB:

Dim e As PaintEventArgs

 

Me.OnPaint(e)

In this article I will tell you that how we can fill an ellipse with an image of an image.

Make an object of garaphics.ClientSize.Width and  ClientSize.height, these two properties gives you the width and height of the client area respectively. The return type of these properties  is an integer and to set them an integer is required. The next function is the drawImage(). This function has 29 overloaded methods,depending on your requirements you can use any of them. The return type of this function is void.

The syntax of the DrawImage() function is:

C#:

g.DrawImage(imageThumbnail,x + (iSquare - imageThumbnail.Width) / 2,y + (iSquare - imageThumbnail.Height) / 2,imageThumbnail.Width, imageThumbnail.Height);

VB:

g.DrawImage(imageThumbnail,x + (iSquare - imageThumbnail.Width) / 2,y + (iSquare - imageThumbnail.Height) / 2,imageThumbnail.Width, imageThumbnail.Height)

To demonstrate make a new window application and write the following code on form’s onpaint event:

C#:

protected override void OnPaint(PaintEventArgs e)

        {

            Graphics g = e.Graphics;

            int cx = ClientSize.Width;

            int cy = ClientSize.Height;

            for (int y = 0; y < cy; y += iSquare)

            {

                for (int x = 0; x < cx; x += iSquare)

                {

                    g.DrawImage(imageThumbnail,x + (iSquare - imageThumbnail.Width) / 2,y + (iSquare - imageThumbnail.Height) / 2,imageThumbnail.Width, imageThumbnail.Height);

                }

            }

        }

VB:

Protected Overrides Sub OnPaint(ByVal e As PaintEventArgs)

    Dim g As Graphics = e.Graphics

    Dim cx As Integer = ClientSize.Width

    Dim cy As Integer = ClientSize.Height

    Dim y As Integer = 0

    While y < cy

        Dim x As Integer = 0

        While x < cx

            g.DrawImage(imageThumbnail, x + (iSquare - imageThumbnail.Width) / 2, y + (iSquare - imageThumbnail.Height) / 2, imageThumbnail.Width, imageThumbnail.Height)

            x += iSquare

        End While

        y += iSquare

    End While

End Sub

Now write the following code on FORM LOAD event:

C#:

private void Form1_Load(object sender, EventArgs e)

        {

            this.Text = "DEVASP APPLICATION";

            ResizeRedraw = true;

            Image image = Image.FromFile("Winter.jpg");

 

            int cxThumbnail, cyThumbnail;

 

            if (image.Width > image.Height)

            {

                cxThumbnail = iSquare;

                cyThumbnail = iSquare * image.Height / image.Width;

            }

            else

            {

                cyThumbnail = iSquare;

                cxThumbnail = iSquare * image.Width / image.Height;

            }

            imageThumbnail = image.GetThumbnailImage(cxThumbnail, cyThumbnail,null, (IntPtr)0);

        }

Vb:

Private Sub Form1_Load(ByVal sender As Object, ByVal e As EventArgs)

    Me.Text = "DEVASP APPLICATION"

    ResizeRedraw = True

    Dim image__1 As Image = Image.FromFile("Winter.jpg")

 

    Dim cxThumbnail As Integer, cyThumbnail As Integer

 

    If image__1.Width > image__1.Height Then

        cxThumbnail = iSquare

        cyThumbnail = iSquare * image__1.Height / image__1.Width

    Else

        cyThumbnail = iSquare

        cxThumbnail = iSquare * image__1.Width / image__1.Height

    End If

    imageThumbnail = image__1.GetThumbnailImage(cxThumbnail, cyThumbnail, Nothing, DirectCast(0, IntPtr))

End Sub

This simple article tells that how to make a thumbnail image in vb and C #.net.

   
Add Article Comment:
Name :
Email Address :
   
Comments :
 
   
<< How to draw a partial image in VB.net - C #.net.

Disclaimer - Privacy
© 2002-2017 DevASP.net