Public Function GetBitmapData(bmpFileName As String) As BitmapData
Using bitmap__1 = DirectCast(Bitmap.FromFile(bmpFileName), Bitmap)
Dim threshold = 127
Dim index = 0
Dim multiplier As Double = 570
' this depends on your printer model. for Beiyang you should use 1000
Dim scale As Double = DirectCast(multiplier / DirectCast(bitmap__1.Width, Double), Double)
Dim xheight As Integer = DirectCast(bitmap__1.Height * scale, Integer)
Dim xwidth As Integer = DirectCast(bitmap__1.Width * scale, Integer)
Dim dimensions = xwidth * xheight
Dim dots = New BitArray(dimensions)
Dim y = 0
While y < xheight
Dim x = 0
While x < xwidth
Dim _x = DirectCast(x / scale, Integer)
Dim _y = DirectCast(y / scale, Integer)
Dim color = bitmap__1.GetPixel(_x, _y)
Dim luminance = DirectCast(color.R * 0.3 + color.G * 0.59 + color.B * 0.11, Integer)
dots(index) = (luminance < threshold)
index += 1
x += 1
End While
y += 1
End While
Return New BitmapData() With { _
.Dots = dots, _
.Height = DirectCast(bitmap__1.Height * scale, Integer), _
.Width = DirectCast(bitmap__1.Width * scale, Integer) _
}
End Using
End Function