Thursday, July 16, 2009

Make GIF image

In this program at first a simple graphics object will be created and then it will be saved as gif image. First open a project as windows application, and then add a button. Form will look as follow


In code window above the class Form1 write following 2 lines to import

Imports System.Drawing
Imports System.Drawing.Imaging

Now double click the button1 and write the following code in side button1_Click sub.

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click

Dim bm As New Bitmap(256, 256)

Dim gr As Graphics = Graphics.FromImage(bm)

gr.Clear(Color.White)

gr.FillRectangle(Brushes.Yellow, 5, 5, bm.Width - 10, bm.Height - 10)

gr.DrawLine(Pens.Green, 0, 0, bm.Width - 1, bm.Height - 1)

gr.DrawLine(Pens.Blue, bm.Width - 1, 0, 0, bm.Height - 1)

bm.Save("c:\image.gif", ImageFormat.Gif)

End Sub


The image will be saved as image.gif file in C drive, and the following image will be saved


image.gif

So lets try.


0 comments:

Post a Comment