1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48
| int main (int argc, char **argv) { if (argc < 2) { printf("%s picture.\n", argv[0]); exit(1); } const char *filename = argv[1];
MagickWandGenesis();
MagickWand *images = NewMagickWand(); if(!MagickReadImage(images, filename)) { printf("E: %s read failed.\n", filename); exit(2); }
printf("Read: %s\n", MagickGetImageFilename(images)); int width = MagickGetImageWidth(images); int height = MagickGetImageHeight(images);
size_t bloblen = width * height; unsigned char *blob = malloc(bloblen); if(!MagickExportImagePixels(images, 0, 0, width, height, "I", CharPixel, blob)) { printf("E: read picture failed.\n"); exit(3); } MagickWand *img = NewMagickWand(); PixelWand *pix = NewPixelWand(); if (!MagickNewImage(img, width, height, pix)) { printf("E: new image failed.\n"); exit(4); } if (!MagickImportImagePixels(img, 0, 0, width, height, "I", CharPixel, blob)) { printf("E: write picture failed.\n"); exit(5); } MagickWriteImage(img, "out.jpg"); printf("Write: out.jpg\n");
free(blob); DestroyPixelWand(pix); DestroyMagickWand(img); DestroyMagickWand(images); MagickWandTerminus(); exit(0); }
|