0

私はこのようなコードを持っています...

CGColorSpaceRef colorSpace = CGColorSpaceCreateDeviceRGB();
CGContextRef ctx = CGBitmapContextCreate(pixelArray, width, height, 8, 4 * width, colorSpace, kCGImageAlphaNoneSkipLast);

CGImageRef createdImage = CGBitmapContextCreateImage (ctx);

uiImage = [[UIImage imageWithCGImage:createdImage] retain];

問題は、バッファー (pixelArray) から CGImage と UIImage を作成すると、バッファーへの書き込み操作が少なくとも 4 倍遅くなることです。これは、iPhone ではなく iPad デバイスでのみ発生します。誰かが同じ問題に直面していますか?ここで何が起こっているのですか?

これが書き込み操作コードで、これらをループで呼び出します (setPixel)...

- (RGBA*) getPixel:(NSInteger)x  y:(NSInteger)y {
    // Bound the co-cordinates.
    x = MIN(MAX(x, 0), width - 1);
    y = MIN(MAX(y, 0), height - 1);

    // yIndexes are pre populated
    return (RGBA*)(&pixelArray[(x + yIndexes[y]) << 2]);
}

- (void) setPixel:(RGBA*)color x:(NSInteger)x  y:(NSInteger)y {
    // Bound the co-cordinates.
    x = MIN(MAX(x, 0), _width);
    y = MIN(MAX(y, 0), _height);

    memcpy([self getPixel:x y:y], color, 3);

    colorDirtyBit = YES;
}
4

1 に答える 1

0

何が悪いのかはわかりませんが、書き込み操作コードの速度が違うのではないかと思います。代わりにこれらの関数を使用せずに生の書き込み操作を試してみませんか?例えば

for(int i = 0; i < bufferlen; i++) {
    pixelArray[i] = i; // or any arbitrary value
}
于 2010-09-30T02:22:04.563 に答える