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

How to stretch a partial image in VB - C

Author: Maliha Atteeq
Download Source Code :

In this simple article you will learn that how to stretch a partial image in vb and C


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:


protected override void OnPaint (PaintEventArgs e)




Dim e As PaintEventArgs



In this article I will tell you that how we can stretch a partial image.

Make an object of garaphics and an array of points. There are four constructors for making the point object, depending on your requirements you can select anyone among them.


Point[] aptDst = { new Point(0, cy / 2),new Point(cx / 2, 0),new Point(cx / 2, cy) };


Dim aptDst As Point() = {New Point(0, cy / 2), New Point(cx / 2, 0), New Point(cx / 2, cy)}

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:


g.DrawImage(image, new Point[] { new Point(cx / 2, 0),new Point(cx,     cy / 2),new Point(0,      cy / 2)});


g.DrawImage(image, new Point[] { new Point(cx / 2, 0),new Point(cx,     cy / 2),new Point(0,      cy / 2)})

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


protected override void OnPaint(PaintEventArgs e)


            Graphics g = e.Graphics;

            int cx = ClientSize.Width;

            int cy = ClientSize.Height;

            Rectangle rectSrc = new Rectangle(95, 5, 50, 55);

            Rectangle rectDst = new Rectangle(0, 0, cx, cy);

            g.DrawImage(image, rectDst, rectSrc, GraphicsUnit.Pixel);



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 rectSrc As New Rectangle(95, 5, 50, 55)

    Dim rectDst As New Rectangle(0, 0, cx, cy)

    g.DrawImage(image, rectDst, rectSrc, GraphicsUnit.Pixel)

End Sub

The above fragment of code will show you the stretch result of the partial image only. Partial image is actually a small portion of the original image. In partial image you are not decreasing the size of the image; you just take out a small portion from the image.

Now write the following code on FORM LOAD event:


private void Form1_Load(object sender, EventArgs e)


            this.Text = "DEVASP APPLICATION";




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


End Sub

This simple article tells that how to stretch a partial image in vb and C

Add Article Comment:
Name :
Email Address :
Comments :
<< Resize bitmap image using lowest and highest quality interpolation mode in –

Disclaimer - Privacy
© 2002-2017