我試圖將HBITMAP轉換爲IWICBitmap,並且遇到了相當多的麻煩。我發現的功能:從HBITMAP轉換到IWICBitmap
CreateBitmapFromHBITMAP();
但我不能得到它的工作。這裏是我如何使用它:
void camera_avtcam_ex_t::GrabAsyncFrame(ULONG frameId, IWICImagingFactory* pWicFactory, IWICBitmap** outputBitmap, bool* pAbort)
{
QueueCamFrame();
HBITMAP transferbitmap;
GetFeatureAndRunAcquisitionStart(transferbitmap); //returns transferbitmap
//as a valid HBITMAP
//This HBITMAP works, I can save it to a file and/or print
//it to the screen and the image is displayed properly
pWicFactory->CreateBitmapFromHBITMAP(transferbitmap, NULL, WICBitmapUseAlpha, outputBitmap);
}
執行的代碼在函數最後一行導致訪問衝突錯誤。
右邊的叫這個GrabAsyncFrame()
功能之前,我創造它需要像這樣的參數:我有種懷疑設定pWicFactory爲NULL,然後後使用它很快
ULONG frameId = 0;
IWICImagingFactory* pWicFactory = NULL;
IWICBitmap** outputBitmap = new IWICBitmap*;
bool* pAbort = NULL;
theCamera.GrabAsyncFrame(frameId, pWicFactory, outputBitmap, pAbort);
。但我找不出任何其他方式來初始化IWICImagingFactory對象。
所以我的問題是:新問題發佈如下。
編輯:如果我嘗試使用new
初始化pWicFactory,我得到一個消息說
Error: object of abstract class type "IWICImagingFactory" is not allowed.
EDIT2:
確認設置pWicFactory爲NULL是問題之後,我現在需要知道如何正確初始化IWICImagingFactory對象指針。這就是我與現在的工作:
ULONG frameId = 0;
IWICImagingFactory* pWicFactory = NULL;
/*new code*/CoCreateInstance(CLSID_WICImagingFactory, NULL, CLSCTX_INPROC_SERVER, IID_PPV_ARGS(&pWicFactory));
IWICBitmap** outputBitmap = new IWICBitmap*;
bool* pAbort = NULL;
theCamera.GrabAsyncFrame(frameId, pWicFactory, outputBitmap, pAbort);
問:如何正確初始化IWICImagingFactory對象的指針?
因此,CoCreateInstance調用失敗?將返回值分配給HRESULT變量並在調試器中查看其描述,然後使用該描述編輯問題。 – user1610015 2013-03-15 14:05:42
啊哈。我只需要在使用'CoCreateInstance()'之前調用'CoInitialize(NULL)'。現在工作正常:) – xcdemon05 2013-03-15 14:30:31