iphone – Paint应用程序的OpenGL ES内容的屏幕截图

iphone – Paint应用程序的OpenGL ES内容的屏幕截图,第1张

概述我正在为iPhone制作一个涂料应用程序.在我的代码中,我使用的是包含轮廓图像的imageView,我在其上放置CAEAGLLayer来填充轮廓图像中的颜色.现在我使用函数截取OpenGL ES [CAEAGLLayer]渲染内容的截图: - (UIImage*)snapshot:(UIView*)eaglview{GLint backingWidth1, backingHeight1;// 我正在为iPhone制作一个涂料应用程序.在我的代码中,我使用的是包含轮廓图像的imageVIEw,我在其上放置CAEAGLLayer来填充轮廓图像中的颜色.现在我使用函数截取OpenGL ES [CAEAGLLayer]渲染内容的截图:

- (UIImage*)snapshot:(UIVIEw*)eaglvIEw{Glint backingWIDth1,backingHeight1;// Bind the color renderbuffer used to render the OpenGL ES vIEw// If your application only creates a single color renderbuffer which is already bound at this point,// this call is redundant,but it is needed if you're dealing with multiple renderbuffers.// Note,replace "_colorRenderbuffer" with the actual name of the renderbuffer object defined in your class.glBindRenderbufferOES(GL_RENDERBUFFER_OES,vIEWrenderbuffer);// Get the size of the backing CAEAGLLayerglGetRenderbufferParameterivOES(GL_RENDERBUFFER_OES,GL_RENDERBUFFER_WIDTH_OES,&backingWIDth1);glGetRenderbufferParameterivOES(GL_RENDERBUFFER_OES,GL_RENDERBUFFER_HEIGHT_OES,&backingHeight1);NSInteger x = 0,y = 0,wIDth = backingWIDth1,height = backingHeight1;NSInteger dataLength = wIDth * height * 4;glubyte *data = (glubyte*)malloc(dataLength * sizeof(glubyte));// Read pixel data from the framebufferglPixelStorei(GL_PACK_AlignmENT,4);glreadPixels(x,y,wIDth,height,GL_RGBA,GL_UNSIGNED_BYTE,data);// Create a CGImage with the pixel data// If your OpenGL ES content is opaque,use kCGImageAlphaNoneskipLast to ignore the Alpha channel// otherwise,use kCGImageAlphaPremultiplIEdLastCGDataProvIDerRef ref = CGDataProvIDerCreateWithData(NulL,data,dataLength,NulL);CGcolorSpaceRef colorspace = CGcolorSpaceCreateDeviceRGB();CGImageRef iref = CGImageCreate(wIDth,8,32,wIDth * 4,colorspace,kCGBitmapByteOrder32Big | kCGImageAlphaPremultiplIEdLast,ref,NulL,true,kCGRenderingIntentDefault);// OpenGL ES measures data in PIXELS// Create a graphics context with the target size measured in POINTSNSInteger wIDthInPoints,heightInPoints;if (NulL != UIGraphicsBeginImageContextWithOptions) {    // On iOS 4 and later,use UIGraphicsBeginImageContextWithOptions to take the scale into consIDeration    // Set the scale parameter to your OpenGL ES vIEw's contentScaleFactor    // so that you get a high-resolution snapshot when its value is greater than 1.0    CGfloat scale = eaglvIEw.contentScaleFactor;    wIDthInPoints = wIDth / scale;    heightInPoints = height / scale;    UIGraphicsBeginImageContextWithOptions(CGSizeMake(wIDthInPoints,heightInPoints),NO,scale);}else {    // On iOS prior to 4,fall back to use UIGraphicsBeginImageContext    wIDthInPoints = wIDth;    heightInPoints = height;    UIGraphicsBeginImageContext(CGSizeMake(wIDthInPoints,heightInPoints));}CGContextRef cgcontext = UIGraphicsGetCurrentContext();// UIKit coordinate system is upsIDe down to GL/Quartz coordinate system// Flip the CGImage by rendering it to the flipped bitmap context// The size of the destination area is measured in POINTSCGContextSetBlendMode(cgcontext,kCGBlendModecopy);CGContextDrawImage(cgcontext,CGRectMake(0.0,0.0,wIDthInPoints,iref);// RetrIEve the UIImage from the current contextUIImage *image = UIGraphicsGetimageFromCurrentimageContext();UIGraphicsEndImageContext();// Clean upfree(data);CFRelease(ref);CFRelease(colorspace);CGImageRelease(iref);return image;}

使用功能将此屏幕截图与轮廓图像组合:

- (voID)Combine:(UIImage *)Back{UIImage *Front =backgroundImageVIEw.image;//UIGraphicsBeginImageContext(Back.size);  UIGraphicsBeginImageContext(CGSizeMake(640,960));// Draw image1  [Back drawInRect:CGRectMake(0,Back.size.wIDth*2,Back.size.height*2)];  // Draw image2  [Front drawInRect:CGRectMake(0,Front.size.wIDth*2,Front.size.height*2)];  UIImage *resultingImage = UIGraphicsGetimageFromCurrentimageContext();  UIImageWritetoSavedPhotosAlbum(resultingImage,nil,nil);UIGraphicsEndImageContext();

}

使用此功能将此图像保存到photoalbum

-(voID)capturetoPhotoAlbum {[self Combine:[self snapshot:self]];UIAlertVIEw *alert = [[UIAlertVIEw alloc] initWithTitle:@"Success" message:@"Image saved to Photo Album" delegate:nil cancelbuttonTitle:@"OK" otherbuttonTitles:nil];[alert show];[alert release];    }

以上代码正在运行,但屏幕截图的图像质量很差.在画笔的轮廓上,有一个灰色的轮廓.我上传了我的应用程序的截图,这是opengles内容和组合的组合. UIImage的.

有没有办法获得视网膜显示opengles-CAEaglelayer内容的截图.

先感谢您!

解决方法 我不相信这个决议是你的问题.如果您在绘图上出现在屏幕上时没有看到灰色轮廓,则可能是您在保存过程中观察到压缩工件.您的图像可能被保存为质量较低的JPEG图像,其中的瑕疵会出现在锐利的边缘,就像图中的图像一样.

为了解决这个问题,Ben Weiss的答案here提供了以下代码,用于强制将图像作为PNG保存到照片库:

UIImage* im = [UIImage imageWithCGImage:myCGRef]; // make image from CGRefNSData* imdata =  UIImagePNGRepresentation ( im ); // get PNG representationUIImage* im2 = [UIImage imageWithData:imdata]; // wrap UIImage around PNG representationUIImageWritetoSavedPhotosAlbum(im2,nil); // save to photo album

虽然这可能是解决此问题的最简单方法,但您也可以尝试使用多重采样抗锯齿,正如Apple在iOS的OpenGL ES编程指南的“Using Multisampling to Improve Image Quality”部分中所述.根据您的填充率限制,MSAA可能会导致您的应用程序出现一些减速.

总结

以上是内存溢出为你收集整理的iphone – Paint应用程序的OpenGL ES内容的屏幕截图全部内容,希望文章能够帮你解决iphone – Paint应用程序的OpenGL ES内容的屏幕截图所遇到的程序开发问题。

如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。

欢迎分享,转载请注明来源:内存溢出

原文地址: http://outofmemory.cn/web/1080582.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-05-27
下一篇 2022-05-27

发表评论

登录后才能评论

评论列表(0条)

保存