Raw Image to Bmp Image
-
I have un array of byte[] below:
byte[] img = new byte[78000] ... Recept raw data from a fingerprint scanner ...
This array contains the data of a image with 300 of height and 260 of width (total = 300 x 260 = 78000). Each position in the array (byte = 256) is a pixel (256 shades of gray). How I create the Image object with this data? Thanks for all response, :laugh: Alexsander "Axia" Antunes -
I have un array of byte[] below:
byte[] img = new byte[78000] ... Recept raw data from a fingerprint scanner ...
This array contains the data of a image with 300 of height and 260 of width (total = 300 x 260 = 78000). Each position in the array (byte = 256) is a pixel (256 shades of gray). How I create the Image object with this data? Thanks for all response, :laugh: Alexsander "Axia" Antunes -
You can write this to
MemoryStream
withWriteByte
method then pass it in a cunstructor ofBitmap
class or useImage.FromStream
method. Mazy "A bank is a place that will lend you money if you can prove that you don't need it." - Bob HopeThis actually wouldn't work. A Bitmap (as do all images) contain header information. This raw data does not. This is a similar situation with digital cameras and digital SLRs that can save RAW image data. They need to have a program that translates the RAW data into an image.
Microsoft MVP, Visual C# My Articles
-
This actually wouldn't work. A Bitmap (as do all images) contain header information. This raw data does not. This is a similar situation with digital cameras and digital SLRs that can save RAW image data. They need to have a program that translates the RAW data into an image.
Microsoft MVP, Visual C# My Articles
Where I have information about header of BMP images? Thanks for all help!:) Alexsander "Axia" Antunes
-
I have un array of byte[] below:
byte[] img = new byte[78000] ... Recept raw data from a fingerprint scanner ...
This array contains the data of a image with 300 of height and 260 of width (total = 300 x 260 = 78000). Each position in the array (byte = 256) is a pixel (256 shades of gray). How I create the Image object with this data? Thanks for all response, :laugh: Alexsander "Axia" AntunesThe
Bitmap
class and related classes and structs actually support this. You can use the constructorBitmap(int, int, int, PixelFormat, IntPtr)
to create a bitmap of a known size, source format, and the address of the first element in the data buffer. Basically, it uses similar functionality from GDI like theCreateDIBitmap
API (although internally it uses GDI+ APIs). This is untested, but should give you some ideabyte[] img = new byte[7800];
// Fill img
GCHandle gch = GCHandle.Alloc(img);
Bitmap bmp = new Bitmap(300, 260, 2400, PixelFormat.Format25bppRgb,
gch.AddrOfPinnedObject());
gch.Free();I don't currently have any raw data to try it out on, but this seems to be the way that is similar to how it's done in good ol' C/C++. Let me know if it works. My digital camera outputs RAW images and eventually I was going to write a new front end since the one that came with it sucks.
Microsoft MVP, Visual C# My Articles
-
This actually wouldn't work. A Bitmap (as do all images) contain header information. This raw data does not. This is a similar situation with digital cameras and digital SLRs that can save RAW image data. They need to have a program that translates the RAW data into an image.
Microsoft MVP, Visual C# My Articles
-
The
Bitmap
class and related classes and structs actually support this. You can use the constructorBitmap(int, int, int, PixelFormat, IntPtr)
to create a bitmap of a known size, source format, and the address of the first element in the data buffer. Basically, it uses similar functionality from GDI like theCreateDIBitmap
API (although internally it uses GDI+ APIs). This is untested, but should give you some ideabyte[] img = new byte[7800];
// Fill img
GCHandle gch = GCHandle.Alloc(img);
Bitmap bmp = new Bitmap(300, 260, 2400, PixelFormat.Format25bppRgb,
gch.AddrOfPinnedObject());
gch.Free();I don't currently have any raw data to try it out on, but this seems to be the way that is similar to how it's done in good ol' C/C++. Let me know if it works. My digital camera outputs RAW images and eventually I was going to write a new front end since the one that came with it sucks.
Microsoft MVP, Visual C# My Articles
-
Heath Stewart wrote: A Bitmap (as do all images) contain header information Well, what about if he writes them in that stream too? Mazy "A bank is a place that will lend you money if you can prove that you don't need it." - Bob Hope
It would be possible to create all the information and serialize that (not .NET serialization, mind you) that to a stream, but it is incredibly error-prone and pain in the butt. For an app I wrote I did something similar that extracts icons and I have to serialize these correctly using the chain of sturctures required. Believe me, you don't want to do that! As you saw in my other answer, .NET does provide a way to do this. You could always P/Invoke native APIs like
CreateDIBitmap
to accomplish this as well. These basically take minimal information and create and serialize the structures for your. I was about to answer that way when I found that you can't (easily) get aBitmap
from a handle :wtf: and noticed the other constructor I've never cared to find before (that basically does the same thing I was going to mention with native APIs).Microsoft MVP, Visual C# My Articles
-
The
Bitmap
class and related classes and structs actually support this. You can use the constructorBitmap(int, int, int, PixelFormat, IntPtr)
to create a bitmap of a known size, source format, and the address of the first element in the data buffer. Basically, it uses similar functionality from GDI like theCreateDIBitmap
API (although internally it uses GDI+ APIs). This is untested, but should give you some ideabyte[] img = new byte[7800];
// Fill img
GCHandle gch = GCHandle.Alloc(img);
Bitmap bmp = new Bitmap(300, 260, 2400, PixelFormat.Format25bppRgb,
gch.AddrOfPinnedObject());
gch.Free();I don't currently have any raw data to try it out on, but this seems to be the way that is similar to how it's done in good ol' C/C++. Let me know if it works. My digital camera outputs RAW images and eventually I was going to write a new front end since the one that came with it sucks.
Microsoft MVP, Visual C# My Articles
In the code below:
Bitmap bmp = new Bitmap(300, 260, 2400, PixelFormat.Format24bppRgb, gch.AddrOfPinnedObject());
What is the third parameter (2400)? In th VS Documentation is the stride parameter, what is this? Thanks for all, :) Alexsander "Axia" Antunes -
In the code below:
Bitmap bmp = new Bitmap(300, 260, 2400, PixelFormat.Format24bppRgb, gch.AddrOfPinnedObject());
What is the third parameter (2400)? In th VS Documentation is the stride parameter, what is this? Thanks for all, :) Alexsander "Axia" AntunesIt's the number of bites in a single row. Since your image is 300 pixels wide and you're dealing with a
byte[]
, which should actually be 300 to represent 300 bytes. I was multiplying by 8 to get the number of bits, which is incorrect (not sure what I was thinking).Microsoft MVP, Visual C# My Articles
-
It's the number of bites in a single row. Since your image is 300 pixels wide and you're dealing with a
byte[]
, which should actually be 300 to represent 300 bytes. I was multiplying by 8 to get the number of bits, which is incorrect (not sure what I was thinking).Microsoft MVP, Visual C# My Articles
My image is 300 of heigth and 260 of width. How value is for stride? 2080(260 * 8 bits) or 2400 (300 * 8 bits) :) Alexsander "Axia" Antunes
-
It's the number of bites in a single row. Since your image is 300 pixels wide and you're dealing with a
byte[]
, which should actually be 300 to represent 300 bytes. I was multiplying by 8 to get the number of bits, which is incorrect (not sure what I was thinking).Microsoft MVP, Visual C# My Articles
My image is 300 of heigth and 260 of width. How value is for stride? 2080(260 * 8 bits) or 2400 (300 * 8 bits) :) But in 2 cases I have the following error: Additional information: Identification is not fixed. Alexsander "Axia" Antunes
-
My image is 300 of heigth and 260 of width. How value is for stride? 2080(260 * 8 bits) or 2400 (300 * 8 bits) :) Alexsander "Axia" Antunes
No, like I said - I made a mistake. Just use 260 for the value, and swap 260 and 300 for the first two params since I accidentally reversed your width and height.
Microsoft MVP, Visual C# My Articles
-
My image is 300 of heigth and 260 of width. How value is for stride? 2080(260 * 8 bits) or 2400 (300 * 8 bits) :) But in 2 cases I have the following error: Additional information: Identification is not fixed. Alexsander "Axia" Antunes
One what like do you get this? Debug your application and find out exactly where the error is happening.
Microsoft MVP, Visual C# My Articles