0

現在、を使用しUIGraphicsBeginImageContext(resultingImageSize);て画像を作成しています。

しかし、この関数を呼び出すと、の幅が正確にわかりませんresultingImageSize
確かに、私は大量のメモリを消費するある種のビデオ処理を開発しました。最初に処理してから描画することはできません。ビデオ処理中に描画する必要があります。

たとえばUIGraphicsBeginImageContext(CGSizeMake(300, 400));、設定すると、400を超える描画部分が失われます。

では、CGContextの可変サイズを設定したり、メモリ消費が非常に少ないCGContextのサイズを変更したりするソリューションはありますか?

4

1 に答える 1

0

サイズを変更する必要があるたびに、新しい大きなコンテキストを作成することで解決策を見つけました。これが魔法の関数です:

void MPResizeContextWithNewSize(CGContextRef *c, CGSize s) {
    size_t bitsPerComponents = CGBitmapContextGetBitsPerComponent(*c);
    size_t numberOfComponents = CGBitmapContextGetBitsPerPixel(*c) / bitsPerComponents;
    CGContextRef newContext = CGBitmapContextCreate(NULL, s.width, s.height, bitsPerComponents, sizeof(UInt8)*s.width*numberOfComponents,
                                                    CGBitmapContextGetColorSpace(*c), CGBitmapContextGetBitmapInfo(*c));
    // Copying context content
    CGImageRef im = CGBitmapContextCreateImage(*c);
    CGContextDrawImage(newContext, CGRectMake(0, 0, CGBitmapContextGetWidth(*c), CGBitmapContextGetHeight(*c)), im);
    CGImageRelease(im);

    CGContextRelease(*c);
    *c = newContext;
}

ここで提案されているようmemcpyに、たとえば、を使用して最適化できるかどうか疑問に思います。試しましたが、コードがクラッシュします。

于 2013-03-26T13:14:02.013 に答える