Objective c UIImageWriteToSavedPhotosAlbum for PNG在缩略图的透明部分创建随机图像(仅限)

Objective c UIImageWriteToSavedPhotosAlbum for PNG在缩略图的透明部分创建随机图像(仅限),objective-c,ios,opengl-es,uiimage,png,Objective C,Ios,Opengl Es,Uiimage,Png,我有一些很好的代码来读取屏幕或屏幕外缓冲区,并将结果保存到iPad相册中,作为一个透明的PNG。在ipad照片查看器或任何其他图像查看器中查看时,图像都会完美呈现。然而,在ipad的原生照片查看应用程序中,缩略图在缩略图的透明部分显示相册中其他图像的部分 是否有其他人遇到过此问题,如果有,是否找到了解决方法?以下是生成图像的屏幕外(部分)代码: EAGLContext *myContext = [[EAGLContext alloc] initWithAPI:kEAGLRenderingAPIO

我有一些很好的代码来读取屏幕或屏幕外缓冲区,并将结果保存到iPad相册中,作为一个透明的PNG。在ipad照片查看器或任何其他图像查看器中查看时,图像都会完美呈现。然而,在ipad的原生照片查看应用程序中,缩略图在缩略图的透明部分显示相册中其他图像的部分

是否有其他人遇到过此问题,如果有,是否找到了解决方法?以下是生成图像的屏幕外(部分)代码:

EAGLContext *myContext = [[EAGLContext alloc] initWithAPI:kEAGLRenderingAPIOpenGLES1];
[EAGLContext setCurrentContext:myContext];

[... set up render buffer code removed for display ...]

[EAGLContext setCurrentContext:myContext];

ImageTextureManager *imageManager = [[ImageTextureManager alloc] init];
[imageManager loadImageTexture:gAppModel.currentImageRef];
[imageManager release];

glBindRenderbufferOES(GL_RENDERBUFFER_OES, offscreenColorRenderbuffer);

[self renderTransformedImage]; // render the image to the buffer

[myContext presentRenderbuffer:GL_RENDERBUFFER_OES];

// grab image from frameBuffer and return it as UIImage
NSInteger x = 0, y = 0;
NSInteger dataLength = width * height * 4;
GLubyte *data = (GLubyte*)malloc(dataLength * sizeof(GLubyte));

glPixelStorei(GL_PACK_ALIGNMENT, 4);
glReadPixels(x, y, width, height, GL_RGBA, GL_UNSIGNED_BYTE, data);

CGDataProviderRef ref = CGDataProviderCreateWithData(NULL, data, dataLength, NULL);
CGColorSpaceRef colorspace = CGColorSpaceCreateDeviceRGB();
CGImageRef iref = CGImageCreate(width, height, 8, 32, width * 4, colorspace,
                                kCGBitmapByteOrder32Big | kCGImageAlphaPremultipliedLast,
                                ref, NULL, true, kCGRenderingIntentDefault);


UIGraphicsBeginImageContext(CGSizeMake(width, height));
CGContextRef cgcontext = UIGraphicsGetCurrentContext();
CGContextSetBlendMode(cgcontext, kCGBlendModeCopy);
CGContextDrawImage(cgcontext, CGRectMake(0.0, 0.0, width, height), iref);
UIImage *image = UIGraphicsGetImageFromCurrentImageContext();  // this call creates an AutoRelease UIImage
NSData* imdata = UIImagePNGRepresentation(image); // get PNG representation
UIImage* myImagePNG = [UIImage imageWithData:imdata]; // wrap UIImage around PNG representation
UIImageWriteToSavedPhotosAlbum(myImagePNG, nil, nil, nil);
UIGraphicsEndImageContext();

多亏了梅德韦德尼克的屏幕外渲染代码:

澄清一下,缩略图中的“随机”部分总是来自相册中的其他图像(即,效果是我想要的图像覆盖在相册中的其他随机图像上)。此外,问题只会出现在iPad硬件上。它不会出现在模拟器中。(应用程序与iPhone不兼容)