While some posts in this topic are more current, this topic was posted before the current version of LEADTOOLS was released and may no longer be applicable.
#1
Posted
:
Tuesday, July 10, 2012 4:52:05 AM(UTC)
Groups: Registered
Posts: 101
Hi,
I am using LEAD Tools 16.5 with .NET 2.0 assemblies for 32 bit operating system.
My application captures the image using third party (NOT LEAD Tools) toolkit.
This third party toolkit returns image pointer (IntPtr) after acquisition is over.
I want to load image from this image pointer in RasterCodecs object.
In LEAD Tools 14.5, I was able to do this using RasterIO.LoadArray2() method, but I do not find equivalent method in 16.5.
Please let me know the way to do this using LT.
#2
Posted
:
Tuesday, July 10, 2012 6:05:08 AM(UTC)
Groups: Registered, Tech Support
Posts: 1,326
Was thanked: 1 time(s) in 1 post(s)
What is the format of the non-lead image in memory?
Is there a way for you to dump the image from memory to a disk file? If yes, can you send it to me in a ZIP or RAR file?
Thanks,
Maen Badwan
LEADTOOLS Technical Support
#3
Posted
:
Tuesday, July 10, 2012 9:06:21 PM(UTC)
Groups: Registered
Posts: 101
Hi,
Image format is raw. Toolkit loads the image in array and returns the pointer to this array.
Of-course there is a way for me to dump the image from memory to disk file. But being a good developer, i want to avoid this to improve the performance.
#4
Posted
:
Wednesday, July 11, 2012 5:33:38 AM(UTC)
Groups: Registered, Tech Support
Posts: 1,326
Was thanked: 1 time(s) in 1 post(s)
I only asked for the data to take a look at it and suggest the suitable approach for loading it. I am NOT suggesting this as a solution in your project. However, since you specified it's raw pixel data, this is enough for me.
If you have raw uncompressed data, and you already know the raw data information (Width, Height, View Perspective, color order, BPP, etc.), you can load the image from the image pointer (IntPtr) by using the following code:
+---------------------+
private void button1_Click(object sender, EventArgs e)
{
RasterCodecs _codecs = new RasterCodecs();
_codecs.LoadInformation += new EventHandler<CodecsLoadInformationEventArgs>(_codecs_LoadInformation);
//Note: ptr is the IntPtr that has the address of pixel data.
byte[] buffer = new byte[RawDataLength];
System.Runtime.InteropServices.Marshal.Copy(ptr, buffer, 0, RawDataLength);
System.IO.MemoryStream MemStr = new System.IO.MemoryStream(buffer);
MemStr.Seek(0, System.IO.SeekOrigin.Begin);
RasterImage MyImage = _codecs.Load(MemStr);
rasterImageViewer1.Image = MyImage;
}
void _codecs_LoadInformation(object sender, CodecsLoadInformationEventArgs e)
{
//Set the Raw data load information. Change any values different at your side
e.BitsPerPixel = 24;
e.Format = RasterImageFormat.Raw;
e.Width = 810;
e.Height = 376;
e.ViewPerspective = RasterViewPerspective.TopLeft;
e.Order = RasterByteOrder.Bgr;
e.Pad4 = true;
e.LeastSignificantBitFirst = true;
e.XResolution = 300;
e.YResolution = 300;
}
+---------------------+
Thanks,
Maen Badwan
LEADTOOLS Technical Support
#5
Posted
:
Thursday, September 29, 2016 11:56:26 AM(UTC)
Groups: Registered
Posts: 37
#6
Posted
:
Thursday, September 29, 2016 4:03:18 PM(UTC)
Groups: Tech Support
Posts: 366
Thanks: 1 times
Was thanked: 4 time(s) in 4 post(s)
Hello Matthias,
I see the note you are mentioning. I believe what it's trying to indicate is that you cannot use the RAW filter in combination with both the IO redirection and the other functions it mentions. The reason I think this is the case is because much of our .NET libraries wrap our C function calls. Since this does work in .NET, i would expect it should work in with our C functions as well. I don't have any specific code written to test this out though. If you have written some code and are having a problem with this, can you share the code you are using or a small sample project that illustrates the issue so I can look into it further here?
I would also note that if you're trying to use raw uncompressed memory for your bitmap, using
L_CreateBitmap() and specifying TYPE_USER followed by
L_SetBitmapDataPointer() would be much easier. This would create a bitmap handle where you would manage the memory, so no copy would be created. When creating the bitmap handle, you'd be specifying all of the header information we'd need to "load" the raw data. It just wouldn't go through our workflow to decompress the data.
Edited by moderator Friday, September 30, 2016 6:27:39 AM(UTC)
| Reason: typo
Walter Bates
Senior Support Engineer
LEAD Technologies, Inc.
![LEAD Logo LEAD Logo](https://www.leadtools.com/images/new-site-images/leadtools-logo-header.png)
#7
Posted
:
Monday, October 3, 2016 8:31:00 AM(UTC)
Groups: Registered
Posts: 37
Hi Walter,
thanks for the tip of using L_CreateBitmap. It's been a long while since i used leadtools so i forgot about this :) after implementing this i noticed input data had to be padded to align to 4 bytes. Unfortunately, since I am passing off the bytes from a image raster generated in Java, there is no padding there so I would need an extra copy (i was already making a copy since the bytes are created in java but do not survive the call to other methods on the bitmap down the road). Unless leadtools provides a way to easily pad the rows for me, i guess it's no fit for my use case.
So I tried the RAW file filter again as you suggested, and indeed, it just works! :)
However, I would still be interested to know whether Leadtools offers some built-in padding mechanism somewhere when using the CreateBitmap approach.
matthias
#8
Posted
:
Monday, October 3, 2016 11:57:08 AM(UTC)
Groups: Tech Support
Posts: 366
Thanks: 1 times
Was thanked: 4 time(s) in 4 post(s)
Matthias,
Unfortunately, there isn't a method with LEADTOOLS that will just fix this for you. We do have methods that can help, but this would still need to be something you'd handled within your application. Basically you'd need to create a buffer that is the correct size (could be user-allocated or LEADTOOLS allocated) and then copy the correct amount of data in row-by-row with
L_PutBitmapRow(). If you needed to interpret the data more specifically, you could alternatively set each pixel with
L_PutPixelColor(). The former would be more efficient. If you knew how to align multiple rows at once, you could use
L_PutBitmapRowCol.
Walter Bates
Senior Support Engineer
LEAD Technologies, Inc.
![LEAD Logo LEAD Logo](https://www.leadtools.com/images/new-site-images/leadtools-logo-header.png)
#9
Posted
:
Tuesday, October 4, 2016 7:52:39 AM(UTC)
Groups: Registered
Posts: 37
Hi Walter,
thank you for your answers
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.