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溢出到图像中