3

.gif 画像を抽出することにより、(1024*768) の解像度で 48 フレームを取得しました。そして、これらのフレームをこのような配列に保存しました。

NSMutableArray *splashImages = [[NSMutableArray alloc] init];
    for(int i=1;i <= 48;i ++)
    {
        [splashImages addObject:[UIImage imageNamed:[NSString  stringWithFormat:@"img%d.jpg",i]]];
    }
    [ImageView setAnimationImages:splashImages];
    [ImageView setAnimationDuration:1.0];
    [ImageView startAnimating];

そして、これをUIImageViewに1秒の期間で与えました.アプリケーションを実行すると、スムーズなアニメーションのようになり、スタックすることさえありました.

これに対する解決策はありますか?

4

2 に答える 2

1

Before all, I am afraid that may cause memory warning if you load all 48 images in to memory, check it with Instrument.

================================

You probably need to force it do the decompressing and rendering before, check this link1 and this link2

Try this, it causes the image to decompress, even though the image context is just 1 pixel large.:

UIGraphicsBeginImageContext(CGSizeMake(1, 1));
    [decompressedImage drawAtPoint:CGPointZero];
UIGraphicsEndImageContext();

or something like this:

CGDataProviderRef imageDataProvider = CGDataProviderCreateWithCFData((__bridge CFDataRef)imageData);
    CGImageRef image = CGImageCreateWithJPEGDataProvider(imageDataProvider, NULL, NO, kCGRenderingIntentDefault);
    CGColorSpaceRef colorSpace = CGColorSpaceCreateDeviceRGB();
    CGContextRef bitmapContext = CGBitmapContextCreate(NULL, CGImageGetWidth(image), CGImageGetHeight(image), CGImageGetBitsPerComponent(image), 0, colorSpace, kCGImageAlphaPremultipliedFirst | kCGBitmapByteOrder32Little);
    CGColorSpaceRelease(colorSpace);
    CGContextDrawImage(bitmapContext, CGRectMake(0, 0, CGImageGetWidth(image), CGImageGetHeight(image)), image);

    CGDataProviderRelease(imageDataProvider);
    CGContextRelease(bitmapContext);

    if (image){
        decompressedImage = [UIImage imageWithCGImage:image];
        CGImageRelease(image);
    }

Hope this is helpful.

于 2013-01-24T22:12:28.817 に答える
0

あなたのアプローチはうまくいきません。遭遇する問題の例については、how-to-resolve-memory-crash-in-iphoneloading-images-for-animation-in-uiimageview-iosを参照してください。ムービーを h.264 でエンコードして、AVPlayer で再生した方がよいでしょう。これは、大量のフルスクリーン .gif ファイルを作成するよりもはるかに優れた方法です。

于 2013-06-21T05:08:36.743 に答える