1
我有一個相當標準的RGBA圖像作爲CGImageRef。如何轉換CGImageRef至GraphicsMagick Blob類型?
我期待將其轉換成GraphicsMagick工具Blob
(http://www.graphicsmagick.org/Magick++/Image.html#blobs)
什麼是去調換它的最好方法是什麼?
我有這個,但如果我在pathString
指定PNG8它只能產生一個純黑色的圖像或崩潰:
- (void)saveImage:(CGImageRef)image path:(NSString *)pathString
{
CGDataProviderRef dataProvider = CGImageGetDataProvider(image);
NSData *data = CFBridgingRelease(CGDataProviderCopyData(dataProvider));
const void *bytes = [data bytes];
size_t width = CGImageGetWidth(image);
size_t height = CGImageGetHeight(image);
size_t length = CGImageGetBytesPerRow(image) * height;
NSString *sizeString = [NSString stringWithFormat:@"%ldx%ld", width, height];
Image pngImage;
Blob blob(bytes, length);
pngImage.read(blob);
pngImage.size([sizeString UTF8String]);
pngImage.magick("RGBA");
pngImage.write([pathString UTF8String]);
}