GIF 그림 재생 및 생성
#import
#import
GIF 그림 재생
NSString *gifpath = [[NSBundle mainBundle] pathForResource:@"1.gif" ofType:nil];
NSData *data = [NSData dataWithContentsOfFile:gifpath];
CGImageSourceRef source = CGImageSourceCreateWithData((__bridge CFDataRef)data, NULL);
// gif
size_t count = CGImageSourceGetCount(source);
// NSLog(@"===%zu",count);
NSMutableArray *tempArray = [NSMutableArray array];
for (size_t i = 0; i < count; i++) {
CGImageRef imageref = CGImageSourceCreateImageAtIndex(source, i, NULL);
UIImage *image = [UIImage imageWithCGImage:imageref scale:[UIScreen mainScreen].scale orientation:UIImageOrientationUp];
[tempArray addObject:image];
//
CGImageRelease(imageref);
}
CFRelease(source);
//
// for (int i = 0; i < tempArray.count; i++) {
// NSData *data = UIImagePNGRepresentation(tempArray[i]);
//
// NSArray *path = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
// NSString *gifpath = path[0];
// NSString *pathNum = [gifpath stringByAppendingString:[NSString stringWithFormat:@"%d.png",i]];
//
// [data writeToFile:pathNum atomically:NO];
// }
UIImageView *imageview = [[UIImageView alloc] init];
imageview.bounds = CGRectMake(0, 0, 180, 180);
imageview.center = CGPointMake([UIScreen mainScreen].bounds.size.width/2, [UIScreen mainScreen].bounds.size.height/2);
[self.view addSubview:imageview];
[imageview setAnimationImages:tempArray];
[imageview setAnimationRepeatCount:3];
[imageview setAnimationDuration:2];
[imageview startAnimating];
GIF 이미지 생성
NSMutableArray *images = [NSMutableArray array];
for (int i = 0; i < 24; i++) {
UIImage *image = [UIImage imageNamed:[NSString stringWithFormat:@"Documents%d",i]];//
[images addObject:image];
}
// gif
NSArray *document = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *documentstr = [document objectAtIndex:0];
NSFileManager *filemanager = [NSFileManager defaultManager];
NSString *textDic = [documentstr stringByAppendingString:@"/gif"];
[filemanager createDirectoryAtPath:textDic withIntermediateDirectories:YES attributes:nil error:nil];
NSString *path = [textDic stringByAppendingString:@"test1.gif"];
NSLog(@"===%@",path);
// gif
CGImageDestinationRef destion;
CFURLRef url = CFURLCreateWithFileSystemPath(kCFAllocatorDefault, (CFStringRef)path, kCFURLPOSIXPathStyle, false);
destion = CGImageDestinationCreateWithURL(url, kUTTypeGIF, images.count, NULL);
// NSDictionary *frameDic = [NSDictionary dictionaryWithObjects:[NSMutableDictionary dictionaryWithObjectsAndKeys:[NSNumber numberWithFloat:0.3],(NSString *)kCGImagePropertyGIFDelayTime, nil] forKeys:(NSString *)kCGImagePropertyGIFDelayTime];
NSDictionary *frameDic = [NSDictionary dictionaryWithObject:[NSDictionary dictionaryWithObject:[NSNumber numberWithFloat:0.0f] forKey:(NSString *)kCGImagePropertyGIFDelayTime] forKey:(NSString *)kCGImagePropertyGIFDictionary];
NSMutableDictionary *gifParmdict = [NSMutableDictionary dictionaryWithCapacity:2];
[gifParmdict setObject:[NSNumber numberWithBool:YES] forKey:(NSString *)kCGImagePropertyGIFHasGlobalColorMap];
[gifParmdict setObject:(NSString *)kCGImagePropertyColorModelRGB forKey:(NSString *)kCGImagePropertyColorModel];
[gifParmdict setObject:[NSNumber numberWithInt:8] forKey:(NSString *)kCGImagePropertyDepth];
[gifParmdict setObject:[NSNumber numberWithInt:0] forKey:(NSString *)kCGImagePropertyGIFLoopCount];
NSDictionary *gifProperty = [NSDictionary dictionaryWithObject:gifParmdict forKey:(NSString *)kCGImagePropertyGIFDictionary];
// GIF
for (UIImage *dimage in images) {
CGImageDestinationAddImage(destion, dimage.CGImage, (__bridge CFDictionaryRef)frameDic);
}
CGImageDestinationSetProperties(destion, (__bridge CFDictionaryRef)gifProperty);
CGImageDestinationFinalize(destion);
CFRelease(destion);
이 내용에 흥미가 있습니까?
현재 기사가 여러분의 문제를 해결하지 못하는 경우 AI 엔진은 머신러닝 분석(스마트 모델이 방금 만들어져 부정확한 경우가 있을 수 있음)을 통해 가장 유사한 기사를 추천합니다:
다양한 언어의 JSONJSON은 Javascript 표기법을 사용하여 데이터 구조를 레이아웃하는 데이터 형식입니다. 그러나 Javascript가 코드에서 이러한 구조를 나타낼 수 있는 유일한 언어는 아닙니다. 저는 일반적으로 '객체'{}...
텍스트를 자유롭게 공유하거나 복사할 수 있습니다.하지만 이 문서의 URL은 참조 URL로 남겨 두십시오.
CC BY-SA 2.5, CC BY-SA 3.0 및 CC BY-SA 4.0에 따라 라이센스가 부여됩니다.