LEADTOOLS Support
Imaging
Imaging SDK Questions
HOWTO: Super-quick way to create image from byte array pixel data
This topic and its replies were posted before the current version of LEADTOOLS was released and may no longer be applicable.
#1
Posted
:
Monday, March 3, 2014 4:37:33 AM(UTC)
Groups: Manager, Tech Support
Posts: 367
Was thanked: 1 time(s) in 1 post(s)
The Leadtools.RasterImage class has a constructor that allows you to create a bitmap from pixel data stored in a byte array if the data in the array meets certain conditions, which are:
1. It must be of known width and height.
2. It must be padded to multiples of 4 bytes per line. The sample below achieves this by using a bitmap width of 800 (in itself multiple of 4).
3. The byte order must be known (assumed BGR in this sample).
The code creates a dummy red-filled bitmap the slow way (looping through all pixels), but is only done to demonstrate where the data came from.
const int w = 800, h = 600;
byte[] b =
new byte[w * h * 3]; //3 bytes per pixel
byte B = 0, G = 0, R = 255; //fill red with 0xff and others with zero
for (
int i = 0; i < b.Length; i+=3) //fill entire bitmap with red
{
b[i] = B;
b[i + 1] = G;
b[i + 2] = R;
}
RasterImage redImage =
new RasterImage(
RasterMemoryFlags.User, w, h, 24,
RasterByteOrder.Bgr,
RasterViewPerspective.TopLeft,
null, b, b.Length);
_codecs.Save(redImage, "d:\RedImage.png",
RasterImageFormat.Png, 24);
Amin Dodin
Senior Support Engineer
LEAD Technologies, Inc.
LEADTOOLS Support
Imaging
Imaging SDK Questions
HOWTO: Super-quick way to create image from byte array pixel data
You cannot post new topics in this forum.
You cannot reply to topics in this forum.
You cannot delete your posts in this forum.
You cannot edit your posts in this forum.
You cannot create polls in this forum.
You cannot vote in polls in this forum.