2016-05-12 75 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