Megalith
Well-known member
- Joined
- Aug 21, 2006
- Messages
- 66
- Programming Experience
- 10+
I am trying to copy the contents of a picture box into a bitmap for further manipulation but i have encoutered a problem, what the sample code below does is to copy the original image into a bitmap, wheres i want to copy only the contents of the controls imagespace into the bitmap i wrote a method using this code and extracts color information from each pixel, the procedure was great using a 16 color tiled bmp image but on a 640*480 24bit color bmp file it took 20 minutes before i exited the program. heres my sample :-
is there a way to obtain the actual pixels for the image on screen without having to resort to API?
VB.NET:
Public Structure ColourMap
Public colour As Color
Public count As Integer
End Structure
public sub TestPixels()
Dim colors As New Collection()
Dim map, tMap As ColourMap
Dim instance As Bitmap = CType(PictureBox1.Image, Bitmap)
Dim x, y As Integer
Dim yes As Boolean
Dim test As Color
map.count = 1 : map.colour = Color.White
ProgressBar1.Maximum = instance.Size.Width - 1
For x = 0 To instance.Size.Width - 1
ProgressBar1.Value = x
My.Application.DoEvents()
For y = 0 To instance.Size.Height - 1
test = instance.GetPixel(x, y)
map.Colour = test
map.Count = 1
yes = False
' we now have our map so we need to search the collection for it
' if it exists we add 1 to the count value and return it to the collection
' if not we add it to the collection
If colors.Count > 0 Then
For index As Integer = 1 To colors.Count
tMap = CType(colors(index), ColourMap)
If tMap.Colour = map.Colour Then
tMap.Count += map.Count
colors.Remove(index)
colors.Add(tMap)
yes = True
End If
Next
If yes = False Then
colors.Add(map)
End If
Else
colors.Add(map)
End If
Next
Next
end sub