मैं एनिमेटेड जीआईएफ के रंगों की संख्या को सीमित करने की कोशिश कर रहा हूं (CGImageRef
की सरणी से बनाया गया)।कोर ग्राफिक्स और जीआईएफ रंग तालिका
हालांकि, मुझे वास्तव में कस्टम रंग तालिका सेट करने में कठिनाई हो रही है। क्या किसी को कोर ग्राफिक्स के साथ ऐसा करने का तरीका पता है?
मुझे kCGImagePropertyGIFImageColorMap
पता है। नीचे कुछ परीक्षण कोड हैं (this github gist से भारी उधार लेना - क्योंकि यह kCGImagePropertyGIFImageColorMap
Google का एकमात्र उदाहरण है)।
NSString *path = [@"~/Desktop/test.png" stringByExpandingTildeInPath];
CGDataProviderRef imgDataProvider = CGDataProviderCreateWithCFData((CFDataRef)[NSData dataWithContentsOfFile:path]);
CGImageRef image = CGImageCreateWithPNGDataProvider(imgDataProvider, NULL, true, kCGRenderingIntentDefault);
const uint8_t colorTable[ 8 ] = { 0, 0, 0, 0, 255, 255, 255 , 255};
NSData* colorTableData = [ NSData dataWithBytes: colorTable length: 8 ];
NSMutableDictionary *gifProps = [NSMutableDictionary dictionary];
[gifProps setObject:colorTableData forKey:(NSString *)kCGImagePropertyGIFImageColorMap];
[gifProps setObject:[NSNumber numberWithBool:NO] forKey:(NSString *)kCGImagePropertyGIFHasGlobalColorMap];
NSDictionary* imgProps = [ NSDictionary dictionaryWithObject: gifProps
forKey: (NSString*) kCGImagePropertyGIFDictionary ];
NSURL* destUrl = [NSURL fileURLWithPath:[@"~/Desktop/test.gif" stringByExpandingTildeInPath]];
CGImageDestinationRef dst = CGImageDestinationCreateWithURL((CFURLRef) destUrl, kUTTypeGIF, 1, NULL);
CGImageDestinationAddImage(dst, image, imgProps);
CGImageDestinationSetProperties(dst, (CFDictionaryRef) imgProps);
CGImageDestinationFinalize(dst);
CFRelease(dst);
लेकिन यह एक काले रंग की & सफेद छवि का निर्माण नहीं करता है।
इसके अलावा, मैंने कलर टेबल जानकारी खोजने के लिए एक जीआईएफ खोलने का प्रयास किया है, लेकिन यह थोड़ा सा सहायता प्रदान कर रहा है।
CGImageSourceRef imageSourceRef = CGImageSourceCreateWithURL((CFURLRef) destUrl, NULL);
NSDictionary *dict = (NSDictionary *)CGImageSourceCopyPropertiesAtIndex(imageSourceRef,0, NULL);
CGImageRef img = CGImageSourceCreateImageAtIndex(imageSourceRef, 0, NULL);
printf("Color space model: %d, indexed=%d, rgb = %d\n", CGColorSpaceGetModel(CGImageGetColorSpace(img)), kCGColorSpaceModelIndexed,kCGColorSpaceModelRGB);
NSLog(@"%@", dict);
यह कहता है कि रंग स्थान जीआईएफ के लिए आरजीबी है। फिर भी, अगर मैं अनुक्रमित पीएनजी के साथ उस कोड को आज़माता हूं, तो यह कहता है कि कलर स्पेस अनुक्रमित है।
इसके अलावा, सभी GIFs मैं कोशिश की है एक छवि शब्दकोश कि निम्नलिखित की तरह मोटे तौर पर दिखता है:
{
ColorModel = RGB;
Depth = 8;
HasAlpha = 1;
PixelHeight = 176;
PixelWidth = 314;
"{GIF}" = {
DelayTime = "0.1";
UnclampedDelayTime = "0.04";
};
}
(अगर मैं CGImageSourceCopyProperties(...)
उपयोग करते हैं, यह एक वैश्विक रंग नक्शे का उल्लेख है, लेकिन फिर कोई रंग तालिका है प्रदान की गई)
टैग में ओएस एक्स कहते हैं। – uchuugaka