Home
Search
 
What's New
Index
Books
Links
Q & A
Newsletter
Banners
 
Feedback
Tip Jar
 
C# Helper...
 
XML RSS Feed
Follow VBHelper on Twitter
 
 
 
MSDN Visual Basic Community
 
 
 
 
 
TitleFill a large area one pixel at a time using SetBitmapBits
Keywordsgraphics, SetBitmapBits, GetBitmapBits, pixel
CategoriesGraphics
 
See my book Visual Basic Graphics Programming for more information on graphics in Visual Basic.

Use the GetBitmapPixels helper routine to load the image's pixel values as RGBTriplet structures. Modify the pixel values and use SetBitmapPixels to update the image.

This program uses routines from the book to easily manipulate the pixels as RGBTriplet values.

 
' Get the picture's image.
GetBitmapPixels Picture1, pixels, bits_per_pixel

' Make RGBTriplet values for the new color.
If use_red Then
    to_pixel.rgbRed = 255
Else
    to_pixel.rgbBlue = 255
End If
use_red = Not use_red

wid = UBound(pixels, 1)
hgt = UBound(pixels, 2)
For Y = 0 To hgt - 1
    For X = 0 To wid - 1
        If (X \ 20) Mod 2 = (Y \ 20) Mod 2 Then
            pixels(X, Y) = black_pixel
        Else
            pixels(X, Y) = to_pixel
        End If
    Next X
Next Y

' Display the image.
SetBitmapPixels Picture1, bits_per_pixel, pixels
Picture1.Picture = Picture1.Image
 
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-2010 Rocky Mountain Computer Consulting, Inc.   All rights reserved.
  Updated