12

私はEAGLView(Appleの例から引用)を持っており、このコードを使用してUIImageに正常に変換できます。

- (UIImage *)glToUIImage:(CGSize)size {

NSInteger backingWidth = size.width;
NSInteger backingHeight = size.height;

NSInteger myDataLength = backingWidth * backingHeight * 4;

// allocate array and read pixels into it.
GLuint *buffer = (GLuint *) malloc(myDataLength);
glReadPixels(0, 0, backingWidth, backingHeight, GL_RGBA, GL_UNSIGNED_BYTE, buffer);

// gl renders “upside down” so swap top to bottom into new array.
for(int y = 0; y < backingHeight / 2; y++) {
    for(int x = 0; x < backingWidth; x++) {
        //Swap top and bottom bytes
        GLuint top = buffer[y * backingWidth + x];
        GLuint bottom = buffer[(backingHeight - 1 - y) * backingWidth + x];
        buffer[(backingHeight - 1 - y) * backingWidth + x] = top;
        buffer[y * backingWidth + x] = bottom;
    }
}

// make data provider with data.
CGDataProviderRef provider = CGDataProviderCreateWithData(NULL, buffer, myDataLength, releaseScreenshotData);

// prep the ingredients
const int bitsPerComponent = 8;
const int bitsPerPixel = 4 * bitsPerComponent;
const int bytesPerRow = 4 * backingWidth;
CGColorSpaceRef colorSpaceRef = CGColorSpaceCreateDeviceRGB();
CGBitmapInfo bitmapInfo = kCGBitmapByteOrderDefault;
CGColorRenderingIntent renderingIntent = kCGRenderingIntentDefault;

// make the cgimage
CGImageRef imageRef = CGImageCreate(backingWidth, backingHeight, bitsPerComponent, bitsPerPixel, bytesPerRow, colorSpaceRef, bitmapInfo, provider, NULL, YES, renderingIntent);
CGColorSpaceRelease(colorSpaceRef);
CGDataProviderRelease(provider);

// then make the UIImage from that
UIImage *myImage = [UIImage imageWithCGImage:imageRef];
CGImageRelease(imageRef);

return myImage;

}

void releaseScreenshotData(void *info, const void *data, size_t size) {
free((void *)data);
};

そして、これが私がこのメソッドを使用してUIImageに変換するコードです:

EAGLView *newView = [[EAGLView alloc] initWithImage:photo.originalImage];

[newView reshapeFramebuffer];
[newView drawView:theSlider.tag value:theSlider.value];
//the two lines above are how EAGLViews in Apple's examples are modified


photoItem *newPhoto = [[photoItem alloc] initWithImage:[self glToUIImage:photo.originalImage.size]];

私が抱えている問題は、変換されたUIImageがEAGLViewと同じ色にならない場合があることです。これは、EAGLViewに高い彩度、高いブリグネス、または低いコントラストを適用した場合、およびその他の場合に発生します。たとえば、EAGLViewに高彩度を適用してから、UIImageに変換すると、画像の一部が想定よりも明るくなります。

そのため、この問題は、以前の質問( EAGLViewからUIImageへのタイミングの質問)と同様に、変装したEAGLViewのタイミングの問題であることがわかりました。

4

1 に答える 1

0

それでも気になる人は、以下の私のコメントを参照してください。

トミー、私はついに解決策への道を切り開いた。これは別のEAGLViewタイミングの問題であり(実際にはSaturation中にのみ発生しました)、performSelector:afterDelay:0.0アプローチで修正できました。どうも

また、iOS 5.0をコーディングしている人は、CoreImageとGLKViewを調べることをお勧めします。これらは基本的に、画像のプロパティを調整する作業(私がここで行っているように)とEAGLViewからUIImageへの変換タイプのものをはるかに簡単にします。

于 2011-11-04T04:20:56.063 に答える