iOS 截屏功能代码
来源:互联网 发布:银行家算法代码实现 编辑:程序博客网 时间:2024/05/30 05:06
大家都知道通过同时按iphone和ipad关机键和home键可以进行截图,也可以通过代码编程进行对屏幕的截图。
使用opengles截图并保存代码:
相关连接
-(UIImage *) glToUIImage { NSInteger myDataLength = 1024 * 768 * 4; // allocate array and read pixels into it. GLubyte *buffer = (GLubyte *) malloc(myDataLength); glReadPixels(0, 0, 1024, 768, 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 <768; y++) { for(int x = 0; x <1024 * 4; x++) { buffer2[(767 - y) * 1024 * 4 + x] = buffer[y * 4 * 1024 + 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 * 1024; CGColorSpaceRef colorSpaceRef = CGColorSpaceCreateDeviceRGB(); CGBitmapInfo bitmapInfo = kCGBitmapByteOrderDefault; CGColorRenderingIntent renderingIntent = kCGRenderingIntentDefault; // make the cgimage CGImageRef imageRef = CGImageCreate(1024, 768, 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);}
使用苹果官网截图并保存
相关连接
-(void)ScreenShots{ [self unschedule:@selector(ScreenShots)]; CGSize imageSize = [[UIScreen mainScreen] bounds].size; if (NULL != UIGraphicsBeginImageContextWithOptions) { UIGraphicsBeginImageContextWithOptions(imageSize, NO, 0); } else { UIGraphicsBeginImageContext(imageSize); } CGContextRef context = UIGraphicsGetCurrentContext(); for (UIWindow * window in [[UIApplication sharedApplication] windows]) { if (![window respondsToSelector:@selector(screen)] || [window screen] == [UIScreen mainScreen]) { CGContextSaveGState(context); CGContextTranslateCTM(context, [window center].x, [window center].y); CGContextConcatCTM(context, [window transform]); CGContextTranslateCTM(context, -[window bounds].size.width*[[window layer] anchorPoint].x, -[window bounds].size.height*[[window layer] anchorPoint].y); [[window layer] renderInContext:context]; CGContextRestoreGState(context); } } UIImage *image = UIGraphicsGetImageFromCurrentImageContext(); UIGraphicsEndImageContext(); NSThread *thread=[[NSThread alloc] initWithTarget:self selector:@selector(saveThread:) object:image]; [thread start]; [thread release]; NSLog(@"Suceeded!");}-(void)saveThread:(UIImage*)image{ NSAutoreleasePool *pool=[[NSAutoreleasePool alloc]init]; UIImageWriteToSavedPhotosAlbum(image, self, nil, nil); [pool release];}
- iOS 截屏功能代码
- iOS 截屏功能代码
- iOS 截屏功能代码
- 【代码笔记】iOS-截屏功能
- <iOS>iPhone 应用里实现截屏功能的代码
- iOS 多种截屏功能代码[UIKit and opengles]
- iOS 多种截屏功能代码[UIKit and opengles]
- ios常用功能代码
- IOS 常用功能代码
- 【IOS】截屏功能
- IOS截屏功能
- iOS截屏功能
- iOS截屏功能
- iOS截屏功能
- iOS 截屏功能
- iOS 截屏代码
- iOS 截屏代码
- iOS代码截屏
- sip server比较
- 为什么高可靠性系统也需要监控 ?
- 程序员从初级到中级10个秘诀
- [笔试面试]共同的祖先节点(淘宝2012校招)
- mars老师推荐的学习android路线
- iOS 截屏功能代码
- 镜像网站
- unsigned int nMsgType:8
- ANDROID 为LISTVIEW构造自定义布局
- 集合中装载对象和基本类型的小问题
- 男女用户的不同偏好:扩展型和维护型游戏
- 虚拟机学习总结
- 文档型数据库MongoDB总结
- ora-12514监听程序当前无法识别连接描述符中请求的服务