ImageMagick Uses

    CGColorSpaceRelease(colorSpace);

    CGImageRef cgimage = CGBitmapContextCreateImage(context);

    UIImage *image = [[UIImage alloc] initWithCGImage:cgimage];

 

    MagickBooleanType status;

    MagickWandGenesis();

    MagickWand *wand = NewMagickWand();

//    status = MagickReadImage(wand,[sPath cStringUsingEncoding:NSUTF8StringEncoding]);  //load frmo file

    status = MagickConstituteImage(wand, width, height, "ARGB", CharPixel, bytes); //load from pixel

    if(status == MagickFalse) ThrowWandException(wand);

    status = MagickQuantizeImage(wand, 2, GRAYColorspace, 1, MagickFalse, MagickFalse); //binalization

    if(status == MagickFalse) ThrowWandException(wand);

    status = MagickWriteImage(wand, [sDest cStringUsingEncoding:NSUTF8StringEncoding]);//write to file

    if(status == MagickFalse) ThrowWandException(wand);

 

//wirte to pixel

MagickExportImagePixels(wand, 0, 0, width, height, "ARGB", CharPixel, trgt_image);

 

//wand to UIImage

    const int bitmapBytesPerRow = 4*width;

    const int bitmapByteCount = (bitmapBytesPerRow*height);

    char *trgt_image = malloc(bitmapByteCount);

    status = MagickExportImagePixels(wand, 0, 0, width, height, "ARGB", CharPixel, trgt_image);

    if(status == MagickFalse) ThrowWandException(wand);

    NSLog(@"%d",kCGImageAlphaPremultipliedFirst);

    CGColorSpaceRef colorSpace = CGColorSpaceCreateDeviceRGB();

    CGContextRef context = CGBitmapContextCreate (trgt_image,

                                                  width,

                                                  height,

                                                  8, // bits per component

                                                  bitmapBytesPerRow,

                                                  colorSpace,

                                                  (CGBitmapInfo)kCGImageAlphaPremultipliedFirst);

    CGColorSpaceRelease(colorSpace);

    CGImageRef cgimage = CGBitmapContextCreateImage(context);

    UIImage *image = [[UIImage alloc] initWithCGImage:cgimage];

你可能感兴趣的:(ImageMagick)