Author Topic: Retrive HBitmap from odDbGetPreviewBitmap()  (Read 2509 times)

0 Members and 1 Guest are viewing this topic.

iumike

  • Guest
Retrive HBitmap from odDbGetPreviewBitmap()
« on: March 28, 2010, 05:20:16 PM »
Hello!

I have tried the following code but all the time I get a black bitmap

OdThumbnailImage odImage;
OdStreamBufPtr pFile = odrxSystemServices()->createFile("c:\\Temp\\test.dwg", Oda::kFileRead, Oda::kShareDenyNo, Oda::kOpenExisting);

try
{
        odDbGetPreviewBitmap(pFile, &odImage );
}
catch(...)
{
        return TRUE;
}

bool b= odImage.hasBmp();
if(b)
{
   BITMAPINFO*pInfo;
   pInfo= (BITMAPINFO*)(odImage.bmp.begin() );
   if(!pInfo)
      return TRUE;   

   void *pBuffer;
   HBITMAP hBitmap;

   if ((hBitmap = CreateDIBSection(NULL, pInfo, DIB_RGB_COLORS, &pBuffer, 0, 0)) != NULL)
   {
       ...
   }
}

Any ideea?
Mike

iumike

  • Guest
Re: Retrive HBitmap from odDbGetPreviewBitmap()
« Reply #1 on: March 31, 2010, 11:17:46 AM »
I have asked Bricsys support to help me in this problem and one particular error i have is that the returned type from odDbGetPreviewBitmap() is BITMAPINFOHEADER not BITMAPINFO.
So to resolve the problem I must extract the HBITMAP from a BITMAPINFOHEADER variable

I have study MSDN documentation and found that BITMAPINFOHEADER variable must be converted to BITMAPINFO and after use CreateDIBSection(...)

According to the same MSDN I know that BITMAPINFO is a structure that contain the initial BITMAPINFOHEADER, my problem is that I do not understand how to indicate extra RGBQUAD bmiColors[1] as the declaration below:
typedef struct tagBITMAPINFO {
  BITMAPINFOHEADER bmiHeader;
  RGBQUAD bmiColors[1];
} BITMAPINFO;

To be honest I do not understand why ODA do not supply a simple function like similar ARX - acdbGetPreviewBitmapFromDwg() ?
Mike

LE3

  • Guest
Re: Retrive HBitmap from odDbGetPreviewBitmap()
« Reply #2 on: March 31, 2010, 11:30:43 AM »
I recall using long time ago a public class by cadwerx.net: AcadThumb

Don't have my old code at hand, but if I find something, will try to post.

iumike

  • Guest
Re: Retrive HBitmap from odDbGetPreviewBitmap()
« Reply #3 on: March 31, 2010, 02:04:10 PM »
I just simply try to cast BITMAPINFOHEADER to BITMAPINFO but all I've got is just a blank image (so I think the approach is an error)

To be more confusing acordingly to MSDN http://msdn.microsoft.com/en-us/library/dd318229%28VS.85%29.aspx

If you cast the BITMAPINFOHEADER to a BITMAPINFO, the bmiHeader member refers to the BITMAPINFOHEADER and the bmiColors member refers to the first entry in the color table, or the first color mask.

Be aware that if the bitmap uses a color table or color masks, then the size of the entire format structure (the BITMAPINFOHEADER plus the color information) is not equal to sizeof(BITMAPINFOHEADER) or sizeof(BITMAPINFO). You must calculate the actual size for each instance....


Ioan

LE3

  • Guest
Re: Retrive HBitmap from odDbGetPreviewBitmap()
« Reply #4 on: March 31, 2010, 03:35:17 PM »
Look for the cAcadThumb by CAdwerx.net... that class will help you.

Sorry, can't find my code sample here..

I just simply try to cast BITMAPINFOHEADER to BITMAPINFO but all I've got is just a blank image (so I think the approach is an error)

To be more confusing acordingly to MSDN http://msdn.microsoft.com/en-us/library/dd318229%28VS.85%29.aspx

If you cast the BITMAPINFOHEADER to a BITMAPINFO, the bmiHeader member refers to the BITMAPINFOHEADER and the bmiColors member refers to the first entry in the color table, or the first color mask.

Be aware that if the bitmap uses a color table or color masks, then the size of the entire format structure (the BITMAPINFOHEADER plus the color information) is not equal to sizeof(BITMAPINFOHEADER) or sizeof(BITMAPINFO). You must calculate the actual size for each instance....


Ioan

LE3

  • Guest
Re: Retrive HBitmap from odDbGetPreviewBitmap()
« Reply #5 on: April 01, 2010, 01:44:32 PM »
got the chance to play a little with this a .bmp extractor, but do not know it will be specific for your usage:

http://www.theswamp.org/index.php?topic=32857.new

iumike

  • Guest
Re: Retrive HBitmap from odDbGetPreviewBitmap()
« Reply #6 on: April 02, 2010, 04:21:57 AM »
Thank you very much!!!!
I will play with your code to adapt to what I need!!

Kind regards!
Mike