LEADTOOLS Support
Imaging
Imaging SDK Questions
Re: What's the DIB struct in C#?(Image Pro for .Net V14.0)
This topic and its replies were posted before the current version of LEADTOOLS was released and may no longer be applicable.
#1
Posted
:
Sunday, June 1, 2008 5:02:43 PM(UTC)
Groups: Registered
Posts: 8
My LeadTools version is Image Pro for .Net V14.0 and I'm using it with C#.
I want to get an image's DIB that loaded by IRasterImage. I write as below:
IntPtr ptr = Image.ToDib(RasterConvertToDibType.BitmapInfoHeader);
byte[] temp = new byte[2000];
Marshal.Copy(ptr, temp, 0, 2000);
The Image is IRasterImage type and loaded correctly.
I checked the datas stored in the temp and I can't find the correct BitmapInfoHeader and the pixel's data. In .Net it's GDI+ and the BitmapInfoHeader is not defined. I want to konw what's the BitmapInfoHeader the LEAD used in .NET and how the pixel's data stored in the DIB. That is how can I get a image's info and it's pixels from a DIB returned by IRasterImage.ToDib() Method.
#2
Posted
:
Sunday, June 1, 2008 9:16:54 PM(UTC)
Groups: Registered
Posts: 8
When I turn the DIB handle to a point I can enven move back as below:
IntPtr ptr = Image.ToDib(RasterConvertToDibType.BitmapInfoHeader);
The Image is IRasterImage type and loaded correctly.
unsafe
{
byte* pDib = (byte*)ptr.ToPointer();
pDib -= 1000;//Move the point back.
for (int i = 0; i < 1000; i++)
pDib[i] = 255;// I expect the errors here but it just works!
}
It can works with no errors. I don't know what's happened. Could anybody figure it out? Thanks:)
#3
Posted
:
Monday, June 2, 2008 4:14:43 AM(UTC)
Groups: Guests
Posts: 3,022
Was thanked: 2 time(s) in 2 post(s)
The DIB that results
from the ToDib method in LEADTOOLS is a standard Windows Independent Bitmap.
I'm not sure what you're trying to do with the byte pointer in the code you
posted, but if you use the DIB in a normal way that other DIBs work with but
not ours, please explain what you're doing and I will check it for you.
#4
Posted
:
Monday, June 2, 2008 4:37:07 PM(UTC)
Groups: Registered
Posts: 8
I'm just trying to read the image's data form the DIB.
The original BitmapInfoHeader defined WINDGI.H (VC 6.0) is:
typedef struct tagBITMAPINFOHEADER{
DWORD biSize;
LONG biWidth;
LONG biHeight;
WORD biPlanes;
WORD biBitCount;
DWORD biCompression;
DWORD biSizeImage;
LONG biXPelsPerMeter;
LONG biYPelsPerMeter;
DWORD biClrUsed;
DWORD biClrImportant;
} BITMAPINFOHEADER, FAR *LPBITMAPINFOHEADER, *PBITMAPINFOHEADER;
In c# there is no standard BitmapInfoHeader, so I write one myself according the BitampInfoHeader defined in VC 6.0 GDI as below:
struct BITMAPINFOHEADER{
UInt32 biSize;//DWORD in GDI (VC 6.0)
int biWidth;//LONG in GDI
int biHeight;//LONG in GDI
ushort biPlanes;//WORD in GDI
ushort biBitCount;//WORD in GDI
UInt32 biCompression;//DWORD in GDI
UInt32 biSizeImage;//DWORD in GDI
int biXPelsPerMeter;//LONG in GDI
int biYPelsPerMeter;//LONG in GDI
UInt32 biClrUsed;//DWORD in GDI
UInt32 biClrImportant;//DWORD in GDI
}
IntPtr ptr = Image.ToDib(RasterConvertToDibType.BitmapInfoHeader);
The Image is IRasterImage type and loaded correctly. unsafe
{
BITMAPINFOHEADER*pDib = (BITMAPINFOHEADER*)ptr.ToPointer();//Turn to BitmapInfoHeader
}
When I checked the *pDib I get above and I can't get the correct BitmapInfoHeade. The data stored in the *pDib is a mass.
What I want is how to use the DIB I get in C# returned by IRasterImage. That is how can I read the infomation from the DIB.
Wish for Ur explaination and thanks:)
#5
Posted
:
Tuesday, June 3, 2008 3:43:05 AM(UTC)
Groups: Guests
Posts: 3,022
Was thanked: 2 time(s) in 2 post(s)
I wrote
this code to show that it works. The demo loads any image and uses the ToDib
method and saves it back as BMP.
The project only uses windows calls not LEADTOOLS. The
problem you are facing might be the missing GlobalLock() method in your code.
#6
Posted
:
Tuesday, June 3, 2008 4:35:21 PM(UTC)
Groups: Registered
Posts: 8
Thanks very much o(∩_∩)o...
I missed the GlobalLock() method.
Now it works!
LEADTOOLS Support
Imaging
Imaging SDK Questions
Re: What's the DIB struct in C#?(Image Pro for .Net V14.0)
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.