Ipad 将背景图像加载到GLPaint

Ipad 将背景图像加载到GLPaint,ipad,opengl-es,Ipad,Opengl Es,我正在实现一个应用程序,用手指画画并保存de图像以供以后编辑。但我不知道如何加载保存的预览图像。 我的应用程序基于苹果的GLPaint示例 我正在使用此代码保存图像 - (UIImage *)readImage { int width = self.frame.size.width; int height = self.frame.size.height; NSInteger myDataLength = width * height * 4; // allocate array and re

我正在实现一个应用程序,用手指画画并保存de图像以供以后编辑。但我不知道如何加载保存的预览图像。 我的应用程序基于苹果的GLPaint示例

我正在使用此代码保存图像

- (UIImage *)readImage {
int width = self.frame.size.width;
int height = self.frame.size.height;

NSInteger myDataLength = width * height * 4;
// allocate array and read pixels into it.
GLubyte *buffer = (GLubyte *) malloc(myDataLength);
glReadPixels(0, 0, width, height, 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 < height; y++)
{
    for(int x = 0; x < width * 4; x++)
    {
        buffer2[((height - 1) - y) * width * 4 + x] = buffer[y * 4 * width + 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 * width;
CGColorSpaceRef colorSpaceRef = CGColorSpaceCreateDeviceRGB();
CGBitmapInfo bitmapInfo = kCGBitmapByteOrderDefault;
CGColorRenderingIntent renderingIntent = kCGRenderingIntentDefault;
// make the cgimage
CGImageRef imageRef = CGImageCreate(width, height, bitsPerComponent, bitsPerPixel, bytesPerRow, colorSpaceRef, bitmapInfo, provider, NULL, NO, renderingIntent);
// then make the uiimage from that
UIImage *myImage = [UIImage imageWithCGImage:imageRef];
return myImage;
}

解决了

我在这个链接中得到了一些示例代码


通过此链接,我可以冷保存并重新加载图像。

读取图像的功能不起作用,我现在不知道为什么!GLPaint是一个开始自己项目的糟糕例子。OpenGL新手所造成的混乱是糟糕的。只是说说而已,你是怎么解决的?请回答您的问题与我们分享:)
- (void) writeImage:(UIImage *)Image {
///write the Image to opengl
}