-(void) sepatateGifAnimation:(NSImage *) gifImage
{
NSArray * reps = [gifImage representations];
for (NSImageRep * rep in reps)
{
// find the bitmap representation
if ([rep isKindOfClass:[NSBitmapImageRep class]] == NO)
continue;
// get the bitmap representation
NSBitmapImageRep * bitmapRep = (NSBitmapImageRep *)rep;
// check multiframe gif
int numFrame = [[bitmapRep valueForProperty:NSImageFrameCount] intValue];
if (numFrame == 0)
break;
for (int i = 0; i < numFrame; ++i)
{
// set the current frame
[bitmapRep setProperty:NSImageCurrentFrame withValue:[NSNumber numberWithInt:i]];
NSData *repData = [bitmapRep representationUsingType:NSPNGFileType properties:nil];
[repData writeToFile:[NSString stringWithFormat: @"/Users/mac-d1/work/Untitled13_%02d.png",i] atomically:NO];
// NSImage *image = [[NSImage alloc] initWithData:repData];//NSData to NSImage 转化生成NSImage进行其他的操作。
}
}
[Cocoa]_[初级]_[Cocoa中对GIF动画分解成一帧帧的图片]
最新推荐文章于 2020-11-24 16:20:07 发布