const char file_path[] = "D:/studyplace/workplace/cpp/resource/9.jpg";
const char result_path[] = "D:/studyplace/workplace/cpp/resource/tmp.jpg";
int magick_rotate_stream()
{
int rc = 0;
PixelWand* background_color = NULL;
MagickWand* magick_wand = NULL;
size_t data_size = 0;
unsigned char* image_data = NULL;
FILE* file = NULL;
size_t bytes_written = 0;
MagickWandGenesis();
magick_wand = NewMagickWand();
if (MagickReadImage(magick_wand, file_path) == MagickFalse) {
printf("Failed to read image\n");
rc = -1;
goto l_out;
}
background_color = NewPixelWand();
PixelSetColor(background_color, "#FF0");
if (MagickRotateImage(magick_wand, background_color, 90) == MagickFalse) {
printf("Failed to rotate image\n");
rc = -1;
goto l_e_free;
}
image_data = (unsigned char*)MagickGetImageBlob(magick_wand, &data_size);
file = fopen("D:/studyplace/workplace/cpp/resource/output.png", "wb");
if (file == NULL) {
printf("无法打开文件。\n");
rc = -1;
goto l_e_free;
}
bytes_written = fwrite(image_data, sizeof(unsigned char), data_size, file);
if (bytes_written != data_size) {
printf("写入文件时出现错误。\n");
rc = -1;
goto l_e_free_file;
}
fclose(file);
background_color = DestroyPixelWand(background_color);
magick_wand = DestroyMagickWand(magick_wand);
l_out:
MagickWandTerminus();
return rc;
l_e_free_file:
fclose(file);
l_e_free:
background_color = DestroyPixelWand(background_color);
magick_wand = DestroyMagickWand(magick_wand);
goto l_out;
}
int main() {
magick_rotate_stream();
return 0;
}