Home
Search
 
What's New
Index
Books
Links
Q & A
Newsletter
Banners
 
Feedback
Tip Jar
 
 
 
Old Pages
 
Old Index
Site Map
What's New
 
Books
How To
Tips & Tricks
Tutorials
Stories
Performance
Essays
Links
Q & A
New in VB6
Free Stuff
Pictures
 
 
 
 
 
 
 
TitleFill a large area one pixel at a time using a Bitmap object in VB.NET
Keywordsgraphics, SetPixel, .NET, pixel
CategoriesGraphics
 
See my book Visual Basic Graphics Programming for more information on graphics in Visual Basic.

Create the bitmap and set the pixels. Then set the PictureBox's Image property equal to the Bitmap.

 
' Get the drawing area size.
wid = PictureBox1.ClientRectangle.Width
hgt = PictureBox1.ClientRectangle.Height

' Allocate the form's drawing buffer.
bm = New Bitmap(wid, hgt)

' Get a new color.
If m_UseRed Then
    clr = Color.Blue
Else
    clr = Color.Red
End If
m_UseRed = Not m_UseRed

' Draw the picture's pixels.
For Y = 1 To hgt - 1
    For X = 1 To wid - 1
        If (X \ 20) Mod 2 = (Y \ 20) Mod 2 Then
            bm.SetPixel(X, Y, Color.Black)
        Else
            bm.SetPixel(X, Y, clr)
        End If
    Next X
Next Y

' Display the image.
PictureBox1.Image = bm
 
This program, together with the following programs, compares the speeds of different methods for manipulating an image's pixels one at a time.

 
 
Copyright © 1997-2001 Rocky Mountain Computer Consulting, Inc.   All rights reserved.
  Updated