Welcome Guest! To enable all features, please Login or Register.

Notification

Icon
Error

Options
View
Last Go to last post Unread Go to first unread post
#1 Posted : Monday, March 3, 2014 4:37:33 AM(UTC)

Amin  
Amin

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.
LEAD Logo
 

Try the latest version of LEADTOOLS for free for 60 days by downloading the evaluation: https://www.leadtools.com/downloads

Wanna join the discussion? Login to your LEADTOOLS Support accountor Register a new forum account.

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.

Powered by YAF.NET | YAF.NET © 2003-2024, Yet Another Forum.NET
This page was generated in 0.039 seconds.