簡體   English   中英

CGImageSourceCreateWithURL總是返回nil

[英]CGImageSourceCreateWithURL return always nil

CGImageSourceCreateWithURL始終返回nil。 我正在傳遞[NSURL fileURLWithPath:getImagePath]。 我仔細檢查圖像是否與我傳遞的URL一致。 請在下面找到代碼。

NSURL *imageURL = [self getImageAtTime:i withTitle:@"gifImage"];

if (!imageURL) {
    NSLog(@"imageURL is null");
    return;
}

CGImageSourceRef source = CGImageSourceCreateWithURL((__bridge CFURLRef)imageURL, NULL);

if (source == NULL) {
    NSLog(@"Source is NULL");
}

CGImageDestinationAddImageFromSource(destination, source, i+1, (__bridge CFDictionaryRef)frameProperties);

在創建CGImageSourceRef source = CGImageSourceCreateWithURL((__bridge CFURLRef)imageURL, NULL); 我只是忘了指定圖像的屬性。 這是CGImageSourceCreateWithURL的以下工作代碼

            NSURL *imageURL = [self getImageAtTime:i withTitle:@"gifImage"];

            if (!imageURL) {
                NSLog(@"imageURL is null");
                return;
            }

            CGImageSourceRef source = CGImageSourceCreateWithURL((__bridge CFURLRef)imageURL, NULL);

            if (source == NULL) {
                NSLog(@"Source is NULL");
            }

            //get all the metadata in the image
            NSDictionary *metadata = (__bridge NSDictionary *)CGImageSourceCopyPropertiesAtIndex(source, 0, NULL);

            //make the metadata dictionary mutable so we can add properties to it
            NSMutableDictionary *metadataAsMutable = [metadata mutableCopy];

            NSMutableDictionary *EXIFDictionary = [[metadataAsMutable objectForKey:(NSString *)kCGImagePropertyExifDictionary]mutableCopy];
            NSMutableDictionary *GPSDictionary = [[metadataAsMutable objectForKey:(NSString *)kCGImagePropertyGPSDictionary]mutableCopy];
            NSMutableDictionary *RAWDictionary = [[metadataAsMutable objectForKey:(NSString *)kCGImagePropertyRawDictionary]mutableCopy];
            NSMutableDictionary *GIFDictionary = [[metadataAsMutable objectForKey:(NSString *)kCGImagePropertyGIFDictionary]mutableCopy];

            if(!EXIFDictionary)
                EXIFDictionary = [[NSMutableDictionary dictionary] init];

            if(!GPSDictionary)
                GPSDictionary = [[NSMutableDictionary dictionary] init];

            if(!RAWDictionary)
                RAWDictionary = [[NSMutableDictionary dictionary] init];

            if(!GIFDictionary)
                GIFDictionary = [[NSMutableDictionary dictionary] init];


            [GPSDictionary setObject:@"camera coord Latitude"
                              forKey:(NSString*)kCGImagePropertyGPSLatitude];
            [GPSDictionary setObject:@"camera coord Longitude"
                              forKey:(NSString*)kCGImagePropertyGPSLongitude];
            [GPSDictionary setObject:@"camera GPS Date Stamp"
                              forKey:(NSString*)kCGImagePropertyGPSDateStamp];
            [GPSDictionary setObject:@"camera direction (heading) in degrees"
                              forKey:(NSString*)kCGImagePropertyGPSImgDirection];

            [GPSDictionary setObject:@"subject coord Latitude"
                              forKey:(NSString*)kCGImagePropertyGPSDestLatitude];
            [GPSDictionary setObject:@"subject coord Longitude"
                              forKey:(NSString*)kCGImagePropertyGPSDestLongitude];

            [EXIFDictionary setObject:@"[S.D.] kCGImagePropertyExifUserComment"
                               forKey:(NSString *)kCGImagePropertyExifUserComment];

            [EXIFDictionary setValue:@"69 m" forKey:(NSString *)kCGImagePropertyExifSubjectDistance];

            [GIFDictionary setObject:[NSNumber numberWithFloat:duration/frameCount] forKey:(NSString *)kCGImagePropertyGIFDelayTime];


            //Add the modified Data back into the image’s metadata
            [metadataAsMutable setObject:EXIFDictionary forKey:(NSString *)kCGImagePropertyExifDictionary];
            [metadataAsMutable setObject:GPSDictionary forKey:(NSString *)kCGImagePropertyGPSDictionary];
            [metadataAsMutable setObject:RAWDictionary forKey:(NSString *)kCGImagePropertyRawDictionary];
            [metadataAsMutable setObject:GIFDictionary forKey:(NSString *)kCGImagePropertyGIFDictionary];

            CGImageDestinationAddImageFromSource(destination, source, 0, (__bridge CFDictionaryRef)metadataAsMutable);

            //            CGImageDestinationAddImage(destination, image.CGImage, (__bridge CFDictionaryRef)frameProperties);

            CFRelease(source);

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM