2016-05-12 32 views
-1

我有一個通過ctypes集成Python和C的問題。試圖用MagickWand方法使用python爲圖像加水印

問題是在MagicSteganoImage方法中,此方法返回0,因此無法寫入最終結果。

有人幫我嗎?謝謝大家。

path="path/photo.png" 
markpath="path/mark.png" 
libwand=CDLL("libMagickWand-6.Q16.so.2") 
libwand.MagickWandGenesis() 
mw=libwand.NewMagickWand() 
libwand.MagickReadImage(mw,path) 
mark=libwand.NewMagickWand() 
libwand.MagickReadImage(mark,markpath) 
result=libwand.NewMagickWand() 
result = libwand.MagickSteganoImage(mw,mark,0) 
libwand.MagickWriteImage(result,dest) 

回答

2

必須告訴蟒蛇如何與C API進行交互。

from ctypes import * 
libwand=CDLL("libMagickWand-6.Q16.so.2") 
# Communicated how python should handle ctypes 
libwand.NewMagickWand.restype = c_void_p 
libwand.MagickReadImage.argtypes = (c_void_p, c_char_p) 
libwand.MagickSteganoImage.argtypes = (c_void_p, c_void_p, c_int) 
libwand.MagickSteganoImage.restype = c_void_p 
libwand.MagickWriteImage.argtypes = (c_void_p, c_char_p) 
# ... work 

以及構建錯誤處理以與C-API異常進行交互。

如需更多幫助,請聯繫source code