我跟着本教程(http://www.bit-101.com/blog/?p=1861)注意到,多次保存相同的图像后,质量缓慢下降。OpenGL ES 2.0失去图像质量
除了内存泄漏,这里出了什么问题?它应该为每个像素拉4个字节(rgba)。如果每个像素都被占据,那么损失在哪里?
----------------- 编辑 -----------------
我节省了每当有一个顶点位置变换时,都会从像素数据中获取新图像,然后将这个更改后的图像加载到我的纹理缓冲区中,并重置顶点/索引缓冲区。这样我就可以保持我的变化持续下去,并最终减少颤音。见我的其他SO问题:OpenGL ES 2.0 Vertex Transformation Algorithms
----------------- 编辑 ---------------- -
之前
后
下面是本教程的代码:
-(UIImage *) glToUIImage {
NSInteger myDataLength = 320 * 480 * 4;
// allocate array and read pixels into it.
GLubyte *buffer = (GLubyte *) malloc(myDataLength);
glReadPixels(0, 0, 320, 480, GL_RGBA, GL_UNSIGNED_BYTE, buffer);
// gl renders "upside down" so swap top to bottom into new array.
// there's gotta be a better way, but this works.
GLubyte *buffer2 = (GLubyte *) malloc(myDataLength);
for(int y = 0; y < 480; y++)
{
for(int x = 0; x < 320 * 4; x++)
{
buffer2[(479 - y) * 320 * 4 + x] = buffer[y * 4 * 320 + x];
}
}
// make data provider with data.
CGDataProviderRef provider = CGDataProviderCreateWithData(NULL, buffer2, myDataLength, NULL);
// prep the ingredients
int bitsPerComponent = 8;
int bitsPerPixel = 32;
int bytesPerRow = 4 * 320;
CGColorSpaceRef colorSpaceRef = CGColorSpaceCreateDeviceRGB();
CGBitmapInfo bitmapInfo = kCGBitmapByteOrderDefault;
CGColorRenderingIntent renderingIntent = kCGRenderingIntentDefault;
// make the cgimage
CGImageRef imageRef = CGImageCreate(320, 480, bitsPerComponent, bitsPerPixel, bytesPerRow, colorSpaceRef, bitmapInfo, provider, NULL, NO, renderingIntent);
// then make the uiimage from that
UIImage *myImage = [UIImage imageWithCGImage:imageRef];
return myImage;
}
-(void)captureToPhotoAlbum {
UIImage *image = [self glToUIImage];
UIImageWriteToSavedPhotosAlbum(image, self, nil, nil);
}
当您说“多次”时,是指在同一图像上多次运行此代码,或从相册加载图像然后再保存它?如果是后者,那么我猜你会看到JPEG压缩(我对iOS不熟悉,所以我不能确定图像是以JPEG格式写入的)。 – 2012-03-20 17:31:04
每次存在顶点位置转换时,我都会从像素数据中保存一个新图像,然后将这个更改后的图像加载到我的纹理缓冲区中,并重置顶点/索引缓冲区。这样我就可以保持我的变化持续下去,并最终减少颤音。看到我的其他SO问题:http://stackoverflow.com/questions/9777393/opengl-es-2-0-vertex-transformation-algorithms – 2012-03-20 17:42:27
这是关键信息 - 你应该把它添加到你的问题。 – 2012-03-20 17:49:50