1

Objective-C (ImageIO フレームワークを使用) を使用して GIF に変換している PNG がありますが、アルファ チャネルが奇妙に変換されています。

たとえば、正方形の上に光沢のある半透明のオーバーレイが付いた赤い正方形があり、ある種のベベルのように見えます。画像を PNG として保存してから、objective-c で GIF に変換しようとします。半透明の光沢が存在するセクション全体が変換されると、真っ白になります (または、UIView が UIImage の背後にある色)。

PNG画像の辞書の値を適切に設定していないと思います...では、可能な値は次のとおりです。

kCGImagePropertyPNGInterlaceType

また

kCGImagePropertyPNGsRGBIntent

これは、gifをアニメーションgifに変換してからクリップボードにコピーするためのコードです(これは機能しますが、一部のpngのアルファチャンネルが失われます)

NSString *path = [[NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES) lastObject] stringByAppendingPathComponent:@"animated.gif"];
    CGImageDestinationRef destination = CGImageDestinationCreateWithURL((CFURLRef)[NSURL fileURLWithPath:path],
                                                                        kUTTypeGIF,
                                                                        16,
                                                                        NULL);


    NSMutableDictionary *dict = [NSMutableDictionary dictionaryWithCapacity:5];
    //[dict setObject:(NSString *) ??? forKey:(NSString *)kCGImagePropertyPNGInterlaceType];
    //[dict setObject:(NSString *) ??? forKey:(NSString *)kCGImagePropertyPNGsRGBIntent];

    NSDictionary *frameProperties = [ NSDictionary dictionaryWithObject: dict
                                                                 forKey: (NSString*) kCGImagePropertyPNGDictionary ];




    NSMutableDictionary *dict2 = [NSMutableDictionary dictionaryWithCapacity:5];

    const uint8_t colorTable2[ 9 ] = { 0, 0, 0, 128, 128, 128, 255,255,255};
    NSData* colorTableData2 = [ NSData dataWithBytes: colorTable2 length: 9 ];

    [dict2 setObject:colorTableData2 forKey:(NSString *)kCGImagePropertyGIFImageColorMap];
    [dict2 setObject:[NSNumber numberWithInt:0] forKey:(NSString *)kCGImagePropertyGIFLoopCount];
    [dict2 setObject:[NSNumber numberWithFloat:0.005] forKey:(NSString *)kCGImagePropertyGIFDelayTime];

    NSDictionary *gifProperties = [ NSDictionary dictionaryWithObject: dict2
                                                                 forKey: (NSString*) kCGImagePropertyGIFDictionary ];



    CGImageDestinationAddImage(destination, image1.image.CGImage, (CFDictionaryRef)frameProperties);
    CGImageDestinationAddImage(destination, image2.image.CGImage, (CFDictionaryRef)frameProperties);
    CGImageDestinationAddImage(destination, image3.image.CGImage, (CFDictionaryRef)frameProperties);
    CGImageDestinationAddImage(destination, image4.image.CGImage, (CFDictionaryRef)frameProperties);
    CGImageDestinationAddImage(destination, image5.image.CGImage, (CFDictionaryRef)frameProperties);
    CGImageDestinationAddImage(destination, image6.image.CGImage, (CFDictionaryRef)frameProperties);
    CGImageDestinationAddImage(destination, image7.image.CGImage, (CFDictionaryRef)frameProperties);
    CGImageDestinationAddImage(destination, image8.image.CGImage, (CFDictionaryRef)frameProperties);
    CGImageDestinationAddImage(destination, image9.image.CGImage, (CFDictionaryRef)frameProperties);
    CGImageDestinationAddImage(destination, image10.image.CGImage, (CFDictionaryRef)frameProperties);
    CGImageDestinationAddImage(destination, image11.image.CGImage, (CFDictionaryRef)frameProperties);
    CGImageDestinationAddImage(destination, image12.image.CGImage, (CFDictionaryRef)frameProperties);
    CGImageDestinationAddImage(destination, image13.image.CGImage, (CFDictionaryRef)frameProperties);
    CGImageDestinationAddImage(destination, image14.image.CGImage, (CFDictionaryRef)frameProperties);
    CGImageDestinationAddImage(destination, image15.image.CGImage, (CFDictionaryRef)frameProperties);
    CGImageDestinationAddImage(destination, image16.image.CGImage, (CFDictionaryRef)frameProperties);

    CGImageDestinationSetProperties(destination, (CFDictionaryRef)gifProperties);
    CGImageDestinationFinalize(destination);
    CFRelease(destination);

    NSData *gifData = [[NSData alloc] initWithContentsOfFile:path];

    UIPasteboard *pasteboard = [UIPasteboard generalPasteboard];

    [pasteboard setData:gifData forPasteboardType:@"com.compuserve.gif"];

    [gifData release];
4

0 に答える 0