-
-(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 );
-
}