iOS屏幕截屏
来源:互联网 发布:python 复制对象 编辑:程序博客网 时间:2024/05/04 01:39
大家都知道通过同时按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捕捉屏幕截屏事件
- iOS屏幕截取,截屏办法
- iOS 截屏幕
- ios 截屏幕
- iOS 实现截屏效果 OC保存屏幕为图片
- ios xcode真机调试获取屏幕截屏
- iOS每日一记-------屏幕截屏的妙用
- ios开发点滴-截屏幕方法
- ios 旋转屏幕横竖屏总结
- iOS 判断屏幕是否锁屏
- iOS 判断屏幕是否锁屏
- iOS 屏幕横竖屏切换问题
- IOS强制屏幕横竖屏相互切换
- iOS屏幕(UIViewController)旋转的横竖屏
- C/C++的内存模型
- 英国地沟油燃料航班首飞遭环保人士抗议
- 抱歉,内容审查程序不允许您参观这个站点!-------破解IE分级审查密码
- eclipse 复制项目部署问题
- Windows运行命令
- iOS屏幕截屏
- 字符串公式解析器——使用“逆波兰式算法”及C#实现
- 让你自己写的Android的Launcher成为系统中第一个启动的,也是唯一的Launcher.
- Win32 SDK程序创建一些控件
- Android手机调试无法查看logcat
- 关于JQuery的clone方法无法拷贝data缓存数据的问题
- 140个Google面试问题(转自http://blog.csdn.net/bopgroup/article/details/6514423)
- CKFinderForJava可以用了
- SQL 模糊查询