Robert Dufour said:
Got it needed to do clear on the bitmap and set background to white before
writing the text.
So now what
The first thing I would do is save it as 24 bit and see if your fax program
accepts it. It might be better (and easier for you) to have it convert it as
it may be optimised for faxing. If not you'll need to convert it yourself.
To do this you would create a second bitmap of 1bit and use LockBits to copy
the data quickly. Something like this
dim bitmap2 as Bitmap = new bitmap(bitmap1.Width, bitmap1.Height,
PixelFormat.1Bit)
dim data2 as BitmapData = bitmap2.LockBits(1bit, WriteOnly)
dim data1 as BitmapData = bitmap1.LockBits(24bit, ReadOnly)
dim ptr2 as IntPtr = data2.Scan0
dim ptr1 as IntPtr = data1.Scan0
dim x as int, y as int
dim array1(0 to data1.width * 3 - 1) as byte
dim array2(0 to data2.width / 8 - 1) as byte
for y = 0 to data2.height - 1
Marshal.Copy(ptr1, array1)
for x = 0 to data2.width - 1
'*********
next
Marshal.Copy(array2, ptr2)
ptr1 = ptr1 + data1.Stride
ptr2 = ptr2 + data2.Stride
next
bitmap1.UnlockBits(data1)
bitmap2.UnlockBits(data2)
the **** bit is the tricky part. You need to decide how to convert from 16
million color to 2 color. The simplest would be to convert the color to
grayscale and then anything over a level of 127 would be considered black.
So something like this:
dim r as int = array1(x * 3)
dim g as int = array1(x * 3 + 1)
dim b as int = array1(x * 3 + 2)
dim c as int = CInt(r * 0.2125 + g * 0.7154 + b * 0.0721)
array2(x / 8) = array2(x / 8) * 2
if c > 127 then array2(x / 8) = array2(x / 8) + 1
What this is doing is getting the red, green, blue out of the first array,
then converting it to a grayscale equivelant. Then because the next bitmap
has 8 pixels per byte we need to keep rolling the byte to the left while
adding a pixel to the right most bit (if it is above 127).
This is of the top of my head so likely there'll be some bits you'll need to
fix. THe lockbits function takes a param of a rect the size of the bitmap,
the pixelformat, and whether to read/write etc.
Michael