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 1, 2008 5:02:43 PM(UTC)

fyjin99  
fyjin99

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.


 

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 : Sunday, June 1, 2008 9:16:54 PM(UTC)

fyjin99  
fyjin99

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)

Qasem Lubani  
Guest

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)

fyjin99  
fyjin99

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)

Qasem Lubani  
Guest

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.
File Attachment(s):
ToDib.zip (670kb) downloaded 33 time(s).
 
#6 Posted : Tuesday, June 3, 2008 4:35:21 PM(UTC)

fyjin99  
fyjin99

Groups: Registered
Posts: 8


Thanks very much o(∩_∩)o...
I missed the GlobalLock() method.
Now it works!
 
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.152 seconds.