我设法做一些事情来提高性能:
我确信有这样做的更好的方法,但上述结果在可接受的性能。
-(CGImageRef)newCGImageRenderedInBitmapContext //this is a category on UIImage
{
//bitmap context properties
CGSize size = self.size;
NSUInteger bytesPerPixel = 4;
NSUInteger bytesPerRow = bytesPerPixel * size.width;
NSUInteger bitsPerComponent = 8;
//create bitmap context
unsigned char *rawData = malloc(size.height * size.width * 4);
memset(rawData, 0, size.height * size.width * 4);
CGColorSpaceRef colorSpace = CGColorSpaceCreateDeviceRGB();
CGContextRef context = CGBitmapContextCreate(rawData, size.width, size.height, bitsPerComponent, bytesPerRow, colorSpace, kCGImageAlphaPremultipliedLast | kCGBitmapByteOrder32Big);
//draw image into bitmap context
CGContextDrawImage(context, CGRectMake(0, 0, size.width, size.height), self.CGImage);
CGImageRef renderedImage = CGBitmapContextCreateImage(context);
//tidy up
CGColorSpaceRelease(colorSpace);
CGContextRelease(context);
free(rawData);
//done!
//Note that we're not returning an autoreleased ref and that the method name reflects this by using 'new' as a prefix
return renderedImage;
}
'UIImageView'不够,因为我需要更多的控制动画序列。例如,循环帧1-10,然后播放帧11-20,然后循环帧21-30。 –
为什么不把它们分解成单独的UIImageView? –