Hi,
I have been using acdbGetPreviewBitmapFromDwg for extracting thumbnail image from DWG files and I am using this from a web job that is running continuously for all the requests. Whenever I make a call to the method acdbGetPreviewBitmapFromDwg, it locks the file and never releases for me to delete the file to clear the clutter from the server. Following is my source code,
bool ReadThumbnail(std::wstring filename, std::wstring thumbnailPath, RDwgError^ error)
{
// acdbGetPreviewBitmapFromDwg depends on hostApp being initialized:
RealDwg::RealDwgHostApp hostApp = RealDwg::RealDwgHostApp::Instance();
if (!s_hostAppInitialized && Acad::eOk == acdbSetHostApplicationServices(&hostApp))
s_hostAppInitialized = true;
if (!s_hostAppInitialized)
{
error->Code = 2;
error->Description = "Host App Not Initialized.";
return false;
}
HBITMAP hBitmap = NULL;
HPALETTE hPalette = NULL;
char* filenameCharPointer = new char[1024];
wcstombs(filenameCharPointer, filename.c_str(), 1024);
if (!fopen(filenameCharPointer, "r"))
{
error->Description = "Source file does not exist";
error->Code = 4;
return false;
}
delete filenameCharPointer;
int bitmapresult = acdbGetPreviewBitmapFromDwg(filename.c_str(), &hBitmap, &hPalette);
if (!bitmapresult)
{
error->Description = "Could not get preview bitmap from dwg";
error->Code = 3;
return false;
}
std::cout << "Storing file now" << std::endl;
CImage image;
image.Attach(hBitmap);
image.Save(thumbnailPath.c_str(), Gdiplus::ImageFormatBMP);
std::cout << "File stored successfully" << std::endl;
image.Destroy();
DeleteObject(hBitmap);
DeleteObject(hPalette);
return true;
}
Any help on how can I release the file for the next method to delete it after the thumbnail extraction.
Regards,
Umar
Saving the bitmap is done like this here:
#include <atlimage.h>
#include <Gdiplusimaging.h>
static void AsdkSavePreviewImage(LPCWSTR filename)
{
HBITMAP hBitmap;
HPALETTE hPal;
acdbGetPreviewBitmapFromDwg(filename, &hBitmap, &hPal);
CBitmap bitmap;
bitmap.Attach(hBitmap);
CImage image;
image.Attach(bitmap);
image.Save(_T("C:\\Temp\\myBitmap.bmp"), Gdiplus::ImageFormatBMP);
DeleteObject(hBitmap);
DeleteObject(hPal);
}
If this doesn't work: Is the function called from the "main thread" or from a separate thread?
Is the first code missing fclose?
Can't find what you're looking for? Ask the community or share your knowledge.