Author: Maliha Atteeq
Download Source Code : 1100_Kode.zip
In this simple article you will learn that how to make an isotropic 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 make an isotropic image.
Make an object of garaphics and an object of rectangle class. There are three constructors for making the rectangle object, depending on your requirements you can select anyone among them.
C#:
Rectangle rect = new Rectangle(0, 0, cx, cy);
VB:
Dim rect As New Rectangle(0, 0, cx, 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:
C#:
g.DrawImage(image, rect.X + (rect.Width - sizef.Width) / 2,rect.Y + (rect.Height - sizef.Height) / 2,sizef.Width, sizef.Height);
VB:
g.DrawImage(image, rect.X + (rect.Width - sizef.Width) / 2, rect.Y + (rect.Height - sizef.Height) / 2, sizef.Width, sizef.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)
{
int cx = ClientSize.Width;
int cy = ClientSize.Height;
Graphics g = e.Graphics;
Rectangle rect = new Rectangle(0, 0, cx, cy);
SizeF sizef = new SizeF(image.Width / image.HorizontalResolution, image.Height / image.VerticalResolution); ;
float fScale = Math.Min(rect.Width / sizef.Width, rect.Height / sizef.Height);
sizef.Width *= fScale;
sizef.Height *= fScale;
g.DrawImage(image, rect.X + (rect.Width - sizef.Width) / 2, rect.Y + (rect.Height - sizef.Height) / 2, sizef.Width, sizef.Height);
}
VB:
Protected Overrides Sub OnPaint(ByVal e As PaintEventArgs)
Dim cx As Integer = ClientSize.Width
Dim cy As Integer = ClientSize.Height
Dim g As Graphics = e.Graphics
Dim rect As New Rectangle(0, 0, cx, cy)
Dim sizef As New SizeF(image.Width / image.HorizontalResolution, image.Height / image.VerticalResolution)
Dim fScale As Single = Math.Min(rect.Width / sizef.Width, rect.Height / sizef.Height)
sizef.Width *= fScale
sizef.Height *= fScale
g.DrawImage(image, rect.X + (rect.Width - sizef.Width) / 2, rect.Y + (rect.Height - sizef.Height) / 2, sizef.Width, sizef.Height)
End Sub
The above fragment of code will show you the result of isotropic image and the original image side by side. Isotropic images are identical in all directions; invariant with respect to direction.
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 Object, ByVal e As EventArgs)
Me.Text = "DEVASP APPLICATION"
End Sub
This simple article tells that how to make an isotropic image in vb and C #.net.