Saving preview image of a drawing

By Balaji Ramamoorthy

The “acdbGetPreviewBitmapFromDwg” method returns the HBITMAP of the drawing’s preview image.Here is a sample code to save this preview image as a bitmap.

#include <atlimage.h>

#include <Gdiplusimaging.h>

 

static void AsdkSavePreviewImage(void)

{

    HBITMAP hBitmap;

    HPALETTE hPal;

 

    acdbGetPreviewBitmapFromDwg

                            (

                                _T("C:\\Temp\\FirstFloor.dwg"),

                                &hBitmap,

                                &hPal

                            );

    CBitmap bitmap;

    bitmap.Attach(hBitmap);

 

    CImage image;

    image.Attach(bitmap);

    image.Save(_T("C:\\Temp\\FirstFloor.bmp"), Gdiplus::ImageFormatBMP);

 

    DeleteObject(hBitmap);

    DeleteObject(hPal);

}


Comments

2 responses to “Saving preview image of a drawing”

  1. croxeldyffic Avatar
    croxeldyffic

    Hello,
    very useful code snippet!
    However, I just tried it with AutoCAD Mechanical 2015 and 2017, and it seems, that the system variable THUMBSIZE does not affect the size or resolution of the preview image saved under “C:\Temp\FirstFloor.bmp”.
    Is this the indended behavior?
    Have a nice day!

  2. Without closing the drawing file if we did some modification to drawing and then using the snippet once again. Preview Image is not getting updates.
    Is this the expected behavior?

Leave a Reply to croxeldyfficCancel reply

Discover more from Autodesk Developer Blog

Subscribe now to keep reading and get access to the full archive.

Continue reading