Created
December 11, 2019 16:25
-
-
Save software-mariodiana/552d2c5c0948678a30a683b9ddcdc9b7 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
- (UIImage *)imageFromWand:(MagickWand *)wand | |
{ | |
const char* map = "ARGB"; | |
NSInteger w = MagickGetImageWidth(wand); | |
NSInteger h = MagickGetImageHeight(wand); | |
NSInteger size = strlen(map) * w * h * sizeof(char); | |
void* buffer = (void *)malloc(size); | |
MagickExportImagePixels(wand, 0, 0, w, h, map, CharPixel, buffer); | |
CGColorSpaceRef colorSpace = CGColorSpaceCreateDeviceRGB(); | |
CGContextRef contextRef = | |
CGBitmapContextCreate(buffer, | |
w, | |
h, | |
8, | |
w * strlen(map), | |
colorSpace, | |
kCGImageAlphaPremultipliedFirst); | |
CGImageRef cgImage = CGBitmapContextCreateImage(contextRef); | |
UIImage *image = [[UIImage alloc] initWithCGImage:cgImage]; | |
CGImageRelease(cgImage); | |
CGContextRelease(contextRef); | |
CGColorSpaceRelease(colorSpace); | |
free(buffer); | |
return image; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment