A faster way to draw Bitmap than .SetPixel?

bonedoc

Well-known member
Joined
May 4, 2006
Messages
112
Programming Experience
Beginner
I am using the .setpixel methood to create a bitmap from a datastream. The files are not that big...but it takes about 1 minute to finish it. Is there a faster way to draw a back and white bitmap?

dim bm as bitmap

for x = 1 to bm.width
for y = 1 to dm.height
bm.setpixel(x,y,color.fromagrib)
next
next
 
Could the Bitmap.FromStream method be used here and draw it using the following color matrix...

VB.NET:
Dim cm As ColorMatrix = New ColorMatrix(New Single()() _
                           {New Single() {0.299, 0.299, 0.299, 0, 0}, _
                            New Single() {0.587, 0.587, 0.587, 0, 0}, _
                            New Single() {0.114, 0.114, 0.114, 0, 0}, _
                            New Single() {0, 0, 0, 1, 0}, _
                            New Single() {0, 0, 0, 0, 1}})
 
I am trying to compare your code to mine. I wonder if there is a way to merge them? I basically have the bytes in an array (mybuffer) that I got from a stream. I then create a color.fromArgb and them set the pixel. Works...but takes forever...like 30 seconds!

dim Histogram(256) as new integer {}

Dim gray As Integer = 0
Dim y As Integer = 0

While y < ImageHeight
Dim x As Integer = 0
While x < ImageWidth

gray = mybuffer(System.Math.Min(System.Threading.Interlocked.Increment(byteco unt), bytecount - 1))

System.Math.Min(System.Threading.Interlocked.Increment(Histogram(gray) ), Histogram(gray) - 1)

Dim mycolor As Color = Color.FromArgb(gray, gray, gray)

myImage.SetPixel(x, y, mycolor)





System.Math.Min(System.Threading.Interlocked.Increment(x), x - 1)
End While
System.Math.Min(System.Threading.Interlocked.Increment(y), y - 1)
End While
 
Last edited:
Back
Top