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 : Sunday, June 26, 2005 5:47:43 PM(UTC)

Don  
Don

Groups: Registered
Posts: 1


Hi,

I am experiencing some problems in using Lead TOOLS Raster Imaging Pro for .NET. The platform I am using is Windows XP Pro., the IDE is VS .Net 2003, and language is c#.


What I am trying to do is to display an image from image data, which is stored in an integer array. The following is the sample code:

int [] imageBuffer = new int[imageWidth * imageHeight];

Byte [] imageData = new byte[Buffer.ByteLength(imageBuffer)];

// load imageBuffer from a local function

Buffer.BlockCopy( imageBuffer, 0, imageData, 0, imageData.Length);

rasterImageViewer1.Image.SetUserData(imageData);

The error message I got is: An unhandled exception of type "System.NullReferenceException" occurred in xxxxx.exe. Additional information: Object reference not set to an instance of an object.

Can you please send me an example showing how to load an image from image data instead of image file. In this case, the image data is stored in an integer array.

Thanks in advance and look forward to your advice.

Best wishes

Don

 

 

 

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.

#2 Posted : Wednesday, November 23, 2005 4:01:58 AM(UTC)

Kousay  
Kousay

Groups: Registered
Posts: 8


Don,

You need to create the IRasterImage object first using RasterMemoryFlags.User then assign the data using SetUserData.  The data must be valid (has the correct width, height, bits/pixel and bytes/line).

See if the following example helps.
Thanks,
Kousay


rasterImageViewer1.Image = SetUserDataTest();
private IRasterImage SetUserDataTest()
{
   // our image is 320 by 200 pixels and is 24 bits/pixel
   int width = 320;
   int height = 200;
   int bitsPerPixel = 24;
   // LEADTOOLS stores the image data scanlines in 32-bit padded lines
   int stride = (((width * bitsPerPixel) + 31) >> 3) & ~3;
   // Allocate the data
   byte[] data = new byte[stride * height];
   // Fill in the data
   byte c = 0;
   for(int y = 0; y < height; y++)
   {
      for(int x = 0; x < width * 3; x += 3)
      {
         data[x + 0 + y * stride] = c;
         data[x + 1 + y * stride] = c;
         data[x + 2 + y * stride] = c;
      }
      c++;
   }
   // Create a new IRasterImage object with user-defined data
   IRasterImage image = new RasterImage(
      RasterMemoryFlags.User,
      width,
      height,
      bitsPerPixel,
      RasterByteOrder.Bgr,
      RasterViewPerspective.TopLeft,
      null,
      null);
   // Set the user data
   image.SetUserData(data);
   return image;
}
 
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-2020, Yet Another Forum.NET
This page was generated in 0.148 seconds.