Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/ios/114.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ios 目标C:使用图像阵列进行Gif转换_Ios_Objective C - Fatal编程技术网

Ios 目标C:使用图像阵列进行Gif转换

Ios 目标C:使用图像阵列进行Gif转换,ios,objective-c,Ios,Objective C,用于使用ImageArray进行gif转换。但当数组包含超过420个图像(近似值)时,我面临内存问题。 这是我的密码: -(void) createGifFromImages:(NSArray*)imageArray :(NSString*)filename { NSDictionary *fileProperties = @{ (id)kCGImagePropertyGIFDictionary: @{

用于使用
ImageArray
进行gif转换。但当数组包含超过420个图像(近似值)时,我面临内存问题。 这是我的密码:

-(void) createGifFromImages:(NSArray*)imageArray :(NSString*)filename
{

    NSDictionary *fileProperties = @{
                                     (id)kCGImagePropertyGIFDictionary: @{
                                             (id)kCGImagePropertyGIFLoopCount: @0, // 0 means loop forever
                                             }
                                     };
    NSURL *documentsDirectoryURL = [[NSFileManager defaultManager] URLForDirectory:NSDocumentDirectory inDomain:NSUserDomainMask appropriateForURL:nil create:YES error:nil];

    filename=[filename stringByAppendingString:@".gif"];
    fileURL = [documentsDirectoryURL URLByAppendingPathComponent:filename];

    NSLog(@"%@",fileURL);
    CGImageDestinationRef destination = CGImageDestinationCreateWithURL((CFURLRef)fileURL, kUTTypeGIF,imageArray.count, NULL);
    CGImageDestinationSetProperties(destination, (CFDictionaryRef)fileProperties);

    UIImage *image;
    for (int i=0;i<imageArray.count;i++) {
        image=imageArray[i];
        NSDictionary *frameDurationProperties = @{
                                                  (id)kCGImagePropertyGIFDictionary: @{
                                                          (id)kCGImagePropertyGIFDelayTime: _durationArray[i % _durationArray.count], // a float (not double!) in seconds, rounded to centiseconds in the GIF data
                                                          }
                                                  };
        CGImageDestinationAddImage(destination, image.CGImage, (CFDictionaryRef)frameDurationProperties);
    }

    if (!CGImageDestinationFinalize(destination)) {
    }

    CFRelease(destination);

}
-(void)createGifFromImages:(NSArray*)imageArray:(NSString*)文件名
{
NSDictionary*文件属性=@{
(id)kCGImagePropertyGIFDictionary:@{
(id)kCGImagePropertyGIFLoopCount:@0,//0表示永远循环
}
};
NSURL*documentsDirectoryURL=[[NSFileManager defaultManager]URLForDirectory:NSDocumentDirectory inDomain:NSUserDomainMask ApprovedForURL:nil创建:是错误:nil];
filename=[filename stringByAppendingString:@“.gif”];
fileURL=[DocumentsDirectoryUrlByAppendingPathComponent:filename];
NSLog(@“%@”,fileURL);
CGImageDestinationRef destination=CGImageDestinationCreateWithURL((CFURLRef)fileURL,kuttypegf,imageArray.count,NULL);
CGImageDestinationSetProperties(目的地,(CFDictionaryRef)文件属性);
UIImage*图像;

对于(int i=0;我不在阵列中存储图像您应该在阵列中存储图像的资产链接,然后通过资产链接获取每个图像以制作gif。如果我存储图像,会出现什么问题?它会失去内存实际上我将gif溢出到图像中。我不在阵列中存储图像。您应该存储图像的资产链接我n数组,然后通过资产链接获取每个图像以生成gif。如果我存储图像,会出现什么问题?它会失去内存。实际上,我将gif溢出到图像中