' Klaus's routine from somewhere in this forum. Faster than getting pixels one by one
Sub getPixels(bmp AsBitmap, offset As Int, stride As Int, x As Int, y As Int, width As Int, height As Int) As Int()
Dim jo = bmp AsJavaObject
Dim pixels(width * height) As Int
jo.RunMethod("getPixels", ArrayAs Object(pixels, offset, width, x, y, width, height))
Return pixels
End Sub
'Call this routine once you have your bitmap converted to monochrome with whatever library you use
Sub Get1bitPerPixelArrayFromMyMonochromeBitmap(mb as Bitmap) as Byte()
Dim size as int = mb.width*mb.height
Dim myPixels() as int = getPixels(mb,0,mb.width,0,0,mb.width,mb.height)
Dim myPrinterArray(size/8 + 1) as byte
Dim myThreshold as int = 128 'or whatever
Dim val as int
Dim index as int=0
for row=0 to mb.height-1
for col=0 to (mb.width/8)-1 'assume mb.width is multiple of 8 otherwise we will need padding
val=0
for numBit=0 to 7
if Bit.And(mypixels(mb.width*row + 8*col + num_bit),0xFF)>myThreshold Then
val = Bir.Or(val,Bit.ShiftRight(0x80,numBit))
end if
next
myPrinterArray(index)=val
index=index+1
next
next
Return(myPrinterArray)
End Sub