Advertise Mobile SDKs Books Events Forum News Social Networking Support Us
Follow @iphonedevsdk on Twitter

Interface 2, Advanced iOS
Mockup & Code Gen
($9.99)

Make your own iPhone apps
and run them live!
(free)

Pic Frame Dynamo: Photo Editing
($0.99)

Abiliator
($1.99)

Want your application or service advertised on iPhone Dev SDK?

Go Back   iPhone Dev SDK Forum

View Single Post
Old 12-08-2009, 12:15 PM   #1 (permalink)
specktro
Registered Member
 
Join Date: Dec 2009
Posts: 4
specktro is on a distinguished road
Question grab an image from OpenGL ES context

I've been working with OpenGL ES to modify an application which allows to capture a user's signature. Now i can draw freehand on the screen but now i need to keep that signature into an image. I found this code which just draws a completely black image, i'm new to OpenGL i hope that somebody can help me...

Code:
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]; 
UIImageWriteToSavedPhotosAlbum(myImage, self, nil, nil);
specktro is offline   Reply With Quote
 

» Advertisements
» Stats
Members: 175,387
Threads: 94,003
Posts: 402,459
Top Poster: BrianSlick (7,978)
Welcome to our newest member, latoncefrank
Powered by vBadvanced CMPS v3.1.0

All times are GMT -5. The time now is 06:29 AM.
Powered by vBulletin® Version 3.8.0
Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.