picturebox getpixel

cyrus_xi
07-08-2006, 05:17 PM
How do i use getpixel and setpixel with an image loaded into a picturebox? Do i have to convert it to bmp and then set it back in the picturebox? How would i do that?

Chris Ara
07-08-2006, 08:37 PM
your best bet is to create a bitmap from the image like this

Dim TempBmp As New Bitmap(PictureBox1.Image.Size.Width, PictureBox1.Image.Size.Height)
TempBmp = PictureBox1.Image
TempBmp.GetPixel(0, 0)


once your done manipulating the image just make the tempbmp the pictureoboxs image

PictureBox1.Image = TempBmp

jo0ls
07-09-2006, 06:01 AM
If the image uses indexed color (where the actual color values are stored in the palette, and the pixels store the index of the color in the palette), then setpixel won't work. In that case you will need to convert to a non-indexed format first:

Dim TempBmp As New Bitmap(PictureBox1.Image.Size.Width, PictureBox1.Image.Size.Height)
Dim g as Graphics = Graphics.FromImage(TempBmp)
g.DrawImage(PictureBox1.Image, New Rectangle(0,0,TempBmp.Width, TempBmp.Height))
g.dispose
TempBmp.GetPixel(0,0)

EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum