2014-02-24 17 views
0

我得到這個錯誤的Microsoft C++異常:Magick :: ErrorBlob內存位置0x004cf1c8 .. 艾執行以下代碼:未處理的異常與ImageMagick的

#include <Magick++.h> 
#include <iostream> 
using namespace std; 
using namespace Magick; 

int main(int argc,char **argv) 
{ 
    InitializeMagick(*argv); 
    Magick::Image image("100x120", "linen"); 
    image.fillColor("black"); 
    image.write("test.png");// if i comment this line there is no more error at the execution 
    return 0; 
} 

回答

0

我做了一些改變來處理異常,這段代碼對我來說很有用,在VC++ 2013 64bit上編譯。

這裏是輸出test.png

另外,還要確保你有寫權限,因爲ErrorBlob是一個IO子系統錯誤。

#include <Magick++.h> 
#include <iostream> 
using namespace std; 
using namespace Magick; 
int main(int argc,char **argv) 
{ 
    InitializeMagick(*argv); 

    try { 
    Image image("100x120", "linen"); 
    image.fillColor("black"); 
    image.write("test.png"); 
    } 
    catch(Exception &error_) 
    { 
     cout << "Caught exception: " << error_.what() << endl; 
     return 1; 
    } 
    return 0; 
} 
+0

我得到這個錯誤:捕獲異常:sampleapp.exe UnableToOpenBlob'#FAFAF0F0E6E6':沒有這樣的文件r目錄@ error/blob.c/OpenBlob/2643 – user3347598

+0

'blob'函數用於打開流,文件和字符串,作爲圖像數據的可能來源。你得到的錯誤是因爲該庫出於某種原因無法找到它的配置文件。也許它缺少您的機器上特定安裝所需的一些環境設置。嘗試在安裝文件夾內執行以進行測試。 ImageMagick目錄中的 –

+0

? – user3347598

0

我建議,你趕上由Magick實現拋出的異常Exception,其寫入cout和揣摩發生了什麼事:

#include <Magick++.h> 
#include <iostream> 
using namespace std; 
using namespace Magick; 

int main(int argc,char **argv) 
{ 
    InitializeMagick(*argv); 
    Magick::Image image("100x120", "linen"); 
    try { 
     image.fillColor("black"); 
     image.write("test.png"); // this line causes the error 
    } catch (const Exception& e) { 
     cout << e.what() << endl; 
    } 
    return 0; 
} 

錯誤你本身原始示例中的e僅告訴您MS的運行時庫無法處理此異常類型。

+0

我得到這個錯誤:捕獲異常:sampleapp.exe UnableToOpenBlob '#FAFAF0F0E6E6':沒有這樣的文件[R目錄@錯誤/ blob.c/OpenBlob/2643 – user3347598