R
RB0135
Hi All,
I have some Windows BMP, 1BPP, monochrome files that I need to get the
raw data from to load a graphics buffer on a Roll Printer (which I
know can be done). Lets forget about the Roll Printer in this equation
as I am not sure I am getting the correct "raw" image from the file.
However, when I print what I think is the raw data, I get the image
size, but the information within the image looks nothing like it
should be, and looks like it is an out of sync TV, or interlaced not
progressive. But, the image itself is unreadable, nothing looking even
remotely to the original.
What I need to verify (or am asking for help) is to get the raw data
out of the bitmap file correctly. Here is some code that I use to get
the raw data (I think).
Dim bmBitmap As Image = New Bitmap("test.bmp")
(also tried Dim bmBitmap As bitmap= New Bitmap("test.bmp") )
Dim raw As System.Drawing.Imaging.BitmapData = Nothing 'used to get
attributes of the image
Dim rawImage() As Byte = Nothing 'the image as a byte[]
Try
'Freeze the image in memory
raw = bmbitmap.LockBits(New Rectangle(0, 0,
bmbitmap.Width, bmbitmap.Height),
System.Drawing.Imaging.ImageLockMode.ReadOnly,
Imaging.PixelFormat.Format1bppIndexed)
Dim size As Integer = raw.Height * raw.Stride
rawImage = New Byte(size - 1)
'Copy the image into the byte()
System.Runtime.InteropServices.Marshal.Copy(raw.Scan0,
rawImage, 0, size)
Finally
If Not raw Is Nothing Then
'Unfreeze the memory for the image
bmbitmap.UnlockBits(raw)
End If
End Try
The rawimage is what I try to print.
Am I doing something wrong or am I missing some steps.
I have also tried to load the RAWIMAGE returned bytes in a PictureBox,
with the following code
Dim ms As New IO.MemoryStream(rawimage)
pbPicture.Image = Image.FromStream(ms) <-- errors here
but get the "PARAMETER IS INCORRECT" error message, and I know from
other posts, this is usually because the BYTE data is invalid (or not
raw), although the byte length returned is 2880 bytes, which does
equate to the width*height*8 of the image.
So, to state again, I just need the raw bytes that makeup the image
within the bmp files.. I am sure I am close, but I am also sure I
might be missing out on one step.
Any help/links most appreciated.
Thanks,
Robert
I have some Windows BMP, 1BPP, monochrome files that I need to get the
raw data from to load a graphics buffer on a Roll Printer (which I
know can be done). Lets forget about the Roll Printer in this equation
as I am not sure I am getting the correct "raw" image from the file.
However, when I print what I think is the raw data, I get the image
size, but the information within the image looks nothing like it
should be, and looks like it is an out of sync TV, or interlaced not
progressive. But, the image itself is unreadable, nothing looking even
remotely to the original.
What I need to verify (or am asking for help) is to get the raw data
out of the bitmap file correctly. Here is some code that I use to get
the raw data (I think).
Dim bmBitmap As Image = New Bitmap("test.bmp")
(also tried Dim bmBitmap As bitmap= New Bitmap("test.bmp") )
Dim raw As System.Drawing.Imaging.BitmapData = Nothing 'used to get
attributes of the image
Dim rawImage() As Byte = Nothing 'the image as a byte[]
Try
'Freeze the image in memory
raw = bmbitmap.LockBits(New Rectangle(0, 0,
bmbitmap.Width, bmbitmap.Height),
System.Drawing.Imaging.ImageLockMode.ReadOnly,
Imaging.PixelFormat.Format1bppIndexed)
Dim size As Integer = raw.Height * raw.Stride
rawImage = New Byte(size - 1)
'Copy the image into the byte()
System.Runtime.InteropServices.Marshal.Copy(raw.Scan0,
rawImage, 0, size)
Finally
If Not raw Is Nothing Then
'Unfreeze the memory for the image
bmbitmap.UnlockBits(raw)
End If
End Try
The rawimage is what I try to print.
Am I doing something wrong or am I missing some steps.
I have also tried to load the RAWIMAGE returned bytes in a PictureBox,
with the following code
Dim ms As New IO.MemoryStream(rawimage)
pbPicture.Image = Image.FromStream(ms) <-- errors here
but get the "PARAMETER IS INCORRECT" error message, and I know from
other posts, this is usually because the BYTE data is invalid (or not
raw), although the byte length returned is 2880 bytes, which does
equate to the width*height*8 of the image.
So, to state again, I just need the raw bytes that makeup the image
within the bmp files.. I am sure I am close, but I am also sure I
might be missing out on one step.
Any help/links most appreciated.
Thanks,
Robert