我按照本教程(http://www.bit-101.com/blog/?p=1861)进行了操作,注意到多次保存同一图像后,质量会慢慢下降。
除了内存泄漏,这里出了什么问题?它应该为每个像素拉4个字节(rgba)。如果考虑每个像素,那么损失在哪里?
----------------- 编辑 -----------------
每次进行顶点位置变换时,我都会从像素数据中保存一个新图像,然后将此更改的图像加载到我的纹理缓冲区中,并重置顶点/索引缓冲区。这样我可以保持我的变化持久,并最终使一个不那么波动的扭曲。请参阅我的其他问题: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);
}
答案 0 :(得分:1)
每当你渲染更改的图像时,它(必要)被重新采样 - 也就是说,转换为位图,其中原始像素(纹素)与屏幕网格对齐而不是1 :1个基础。这必然是有损的,因为你丢失了原始图像的一些细节,所以如果再次扭曲图像,与使用不同参数转换原始图像相比,你会得到更糟的结果。