/* 图片路径 */ const char file_path[] = "D:/studyplace/workplace/cpp/resource/9.gif"; const char result_path[] = "D:/studyplace/workplace/cpp/resource/tmp.gif"; /* 普通图片剪切 */ int magick_crop() { int rc = 0; MagickWand* magick_wand = NULL; // 初始化ImageMagick库 MagickWandGenesis(); // 创建MagickWand对象 magick_wand = NewMagickWand(); // 读取图片文件 if (MagickReadImage(magick_wand, file_path) == MagickFalse) { printf("Failed to read image\n"); rc = -1; goto l_out; } // 在 (50, 50) 处裁剪出 100x100 大小的区域 if (MagickCropImage(magick_wand, 100, 100, 50, 50) == MagickFalse) { printf("Failed to crop image\n"); rc = -1; goto l_e_free; } // 保存剪切后的图片 if (MagickWriteImage(magick_wand, result_path) == MagickFalse) { printf("Failed to write image\n"); rc = -1; goto l_e_free; } magick_wand = DestroyMagickWand(magick_wand); l_out: MagickWandTerminus(); return rc; l_e_free: magick_wand = DestroyMagickWand(magick_wand); goto l_out; } int main() { magick_crop(); return 0; }