surface pro3怎么截图怎么进行屏幕截图

iOS中正确的截屏姿势
招聘信息:
昨天写了个用到截屏功能的插件,结果问题不断,今天终于解决好了,把debug过程中所有尝试过的截屏方法都贴出来吧~第一种这是iOS 3时代开始就被使用的方法,它被废止于iOS 7。iOS的私有方法,效率很高。#import
extern&"C"&CGImageRef&UIGetScreenImage();
UIImage&*&screenshot(void)&NS_DEPRECATED_IOS(3_0,7_0);
UIImage&*&screenshot(){
&&&&UIImage&*image&=&[UIImage&imageWithCGImage:UIGetScreenImage()];
&&&&return&
}第二种这是在比较常见的截图方法,不过不支持Retina屏幕。UIImage&*&screenshot(UIView&*);
UIImage&*&screenshot(UIView&*view){
&&&&UIGraphicsBeginImageContext(view.frame.size);
&&&&[view.layer&renderInContext:UIGraphicsGetCurrentContext()];
&&&&UIImage&*image&=&UIGraphicsGetImageFromCurrentImageContext();
&&&&UIGraphicsEndImageContext();
&&&&return&
}第三种从iPhone 4、iPod Touch 4开始,Apple逐渐采用Retina屏幕,于是在iOS 4的SDK中我们有了,上面的截图方法也自然变成了这样。UIImage&*&screenshot(UIView&*)&NS_AVAILABLE_IOS(4_0);
UIImage&*&screenshot(UIView&*view){
&&&&if(UIGraphicsBeginImageContextWithOptions&!=&NULL)
&&&&&&&&UIGraphicsBeginImageContextWithOptions(view.frame.size,&NO,&0.0);
&&&&}&else&{
&&&&&&&&UIGraphicsBeginImageContext(view.frame.size);
&&&&[view.layer&renderInContext:UIGraphicsGetCurrentContext()];
&&&&UIImage&*image&=&UIGraphicsGetImageFromCurrentImageContext();
&&&&UIGraphicsEndImageContext();
&&&&return&
}第四种或许你会说有时Hook的是一个按钮的方法,用第三个方法的话,根本找不到view来传值,不过还好,iOS 7又提供了一些UIScreen的API。UIImage&*&screenshot(void)&NS_AVAILABLE_IOS(7_0);
UIImage&*&screenshot(){
&&&&UIView&*&view&=&[[UIScreen&mainScreen]&snapshotViewAfterScreenUpdates:YES];
&&&&if(UIGraphicsBeginImageContextWithOptions&!=&NULL)
&&&&&&&&UIGraphicsBeginImageContextWithOptions(view.frame.size,&NO,&0.0);
&&&&}&else&{
&&&&&&&&UIGraphicsBeginImageContext(view.frame.size);
&&&&[view.layer&renderInContext:UIGraphicsGetCurrentContext()];
&&&&UIImage&*image&=&UIGraphicsGetImageFromCurrentImageContext();
&&&&UIGraphicsEndImageContext();
&&&&return&
}第五种@interface&SBScreenShotter&:&NSObject
+&(id)sharedI
-&(void)saveScreenshot:(_Bool)arg1;
@end然后直接[[SBScreenShotter&sharedInstance]&saveScreenshot:YES];一道白光之后,咱们就模拟了用户截屏的动作,不过这个方法在只需要截屏时比较好,如果要对屏幕录像(其实就是不断截图)的话,那不得闪瞎了。。而且我们也拿不到UIImage的实例去拼成一个视频呀。即使通过Hook别的类拿到UIImage的实例,这个私有API的效率大概也是达不到30FPS的视频要求的。那么现在我们有5种方法了,第一种是私有API,私有API通常效率和质量都比Documented API的好,可是它在iOS 7以后就被废除了啊,就没有别的了吗?答案当然是————有的!用Private Framework来完成这项任务!直接走底层拿屏幕的缓冲数据,然后生成UIImage的实例。第六种#import&#import&#import&#import&#import&extern&"C"&IOReturn&IOSurfaceLock(IOSurfaceRef&buffer,&uint32_t&options,&uint32_t&*seed);
extern&"C"&IOReturn&IOSurfaceUnlock(IOSurfaceRef&buffer,&uint32_t&options,&uint32_t&*seed);
extern&"C"&size_t&IOSurfaceGetWidth(IOSurfaceRef&buffer);
extern&"C"&size_t&IOSurfaceGetHeight(IOSurfaceRef&buffer);
extern&"C"&IOSurfaceRef&IOSurfaceCreate(CFDictionaryRef&properties);
extern&"C"&void&*IOSurfaceGetBaseAddress(IOSurfaceRef&buffer);
extern&"C"&size_t&IOSurfaceGetBytesPerRow(IOSurfaceRef&buffer);
extern&const&CFStringRef&kIOSurfaceAllocS
extern&const&CFStringRef&kIOSurfaceW
extern&const&CFStringRef&kIOSurfaceH
extern&const&CFStringRef&kIOSurfaceIsG
extern&const&CFStringRef&kIOSurfaceBytesPerR
extern&const&CFStringRef&kIOSurfaceBytesPerE
extern&const&CFStringRef&kIOSurfacePixelF
&&&&kIOSurfaceLockReadOnly&&=0x,
&&&&kIOSurfaceLockAvoidSync&=0x
UIImage&*&screenshot(void);
UIImage&*&screenshot(){
&&&&IOMobileFramebufferConnection&
&&&&kern_return_t&
CoreSurfaceBufferRef&screenSurface&=&NULL;
&&&&io_service_t&framebufferService&=&IOServiceGetMatchingService(kIOMasterPortDefault,IOServiceMatching("AppleH1CLCD"));
if(!framebufferService)
&&&&&&&&framebufferService&=&IOServiceGetMatchingService(kIOMasterPortDefault,IOServiceMatching("AppleM2CLCD"));
if(!framebufferService)
&&&&&&&&framebufferService&=&IOServiceGetMatchingService(kIOMasterPortDefault,IOServiceMatching("AppleCLCD"));
result&=&IOMobileFramebufferOpen(framebufferService,&mach_task_self(),&0,&&connect);
result&=&IOMobileFramebufferGetLayerDefaultSurface(connect,&0,&&screenSurface);
&&&&uint32_t&
&&&&IOSurfaceLock((IOSurfaceRef)screenSurface,&0x,&&aseed);
&&&&size_t&width&=&IOSurfaceGetWidth((IOSurfaceRef)screenSurface);
&&&&size_t&height&=&IOSurfaceGetHeight((IOSurfaceRef)screenSurface);
&&&&CFMutableDictionaryRef&
size_t&pitch&=&width*4,&size&=&width*height*4;
&&&&int&bPE=4;
&&&&char&pixelFormat[4]&=&{'A','R','G','B'};
&&&&dict&=&CFDictionaryCreateMutable(kCFAllocatorDefault,&0,&&kCFTypeDictionaryKeyCallBacks,&&kCFTypeDictionaryValueCallBacks);
&&&&CFDictionarySetValue(dict,&kIOSurfaceIsGlobal,&kCFBooleanTrue);
&&&&CFDictionarySetValue(dict,&kIOSurfaceBytesPerRow,&CFNumberCreate(kCFAllocatorDefault,kCFNumberSInt32Type,&&pitch));
&&&&CFDictionarySetValue(dict,&kIOSurfaceBytesPerElement,&CFNumberCreate(kCFAllocatorDefault,kCFNumberSInt32Type,&&bPE));
&&&&CFDictionarySetValue(dict,&kIOSurfaceWidth,&CFNumberCreate(kCFAllocatorDefault,kCFNumberSInt32Type,&&width));
&&&&CFDictionarySetValue(dict,&kIOSurfaceHeight,&CFNumberCreate(kCFAllocatorDefault,kCFNumberSInt32Type,&&height));
&&&&CFDictionarySetValue(dict,&kIOSurfacePixelFormat,&CFNumberCreate(kCFAllocatorDefault,kCFNumberSInt32Type,&pixelFormat));
&&&&CFDictionarySetValue(dict,&kIOSurfaceAllocSize,&CFNumberCreate(kCFAllocatorDefault,kCFNumberSInt32Type,&&size));
&&&&IOSurfaceRef&destSurf&=&IOSurfaceCreate(dict);
&&&&IOSurfaceAcceleratorRef&outA
&&&&IOSurfaceAcceleratorCreate(NULL,&0,&&outAcc);
&&&&IOSurfaceAcceleratorTransferSurface(outAcc,&(IOSurfaceRef)screenSurface,&destSurf,&dict,NULL);
&&&&IOSurfaceUnlock((IOSurfaceRef)screenSurface,&kIOSurfaceLockReadOnly,&&aseed);
CFRelease(outAcc);
&&&&CGDataProviderRef&provider&=&&CGDataProviderCreateWithData(NULL,&&IOSurfaceGetBaseAddress(destSurf),&(width&*&height&*&4),&NULL);
&&&&CGImageRef&cgImage&=&CGImageCreate(width,&height,&8,
8*4,&IOSurfaceGetBytesPerRow(destSurf),
&CGColorSpaceCreateDeviceRGB(),&kCGImageAlphaNoneSkipFirst&|kCGBitmapByteOrder32Little,provider,&NULL,&YES,&kCGRenderingIntentDefault);
&&&&UIImage&*image&=&[UIImage&imageWithCGImage:cgImage];
&&&&return&
}需要注意的是,第五种方法需要修改一下IOMobileFramebuffer的头文件。typedef&void&*&IOMobileFramebufferCIn the reversed header, IOMobileFramebufferConnection is typedef'd to io_connect_t, which is typedef'd to io_object_t, which is mach_port_t, which is __darwin_mach_port_t, which is __darwin_mach_port_name_t, which is __darwin_natural_t, which is unsigned int! Int just happens to be pointer-sized on 32-bit, but is not under 64-bit。& & & & & & & & & & & & & & & & &——顺便也丢上来吧,解压后放在Project的根目录下。如果你使用的是theos的话,记得在Makefile里写上,YOUR_TWEAK_NAME_PRIVATE_FRAMEWORKS = IOSurface IOKit IOMobileFramebufferYOUR_TWEAK_NAME_CFLAGS = -I./headers/ -I./headers/IOSurface如果是XCode上的Logos Tweak的话,在Build Settings -> Search Paths -> Header Search Paths里面添加一项:$(PROJECT_DIR)/YOUR_PROJECT_NAME/headers, 搜索方式为recursive. 最后在Build Phases里Link上IOSurface IOKit IOMobileFramebuffer这三个私有Framework。
微信扫一扫
订阅每日移动开发及APP推广热点资讯公众号:CocoaChina
您还没有登录!请或
点击量9372点击量7466点击量7398点击量4543点击量4103点击量3825点击量3256点击量3139点击量2808
&2016 Chukong Technologies,Inc.
京公网安备89Surface3的八种截屏方法--Win10版_surface3吧_百度贴吧
&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&签到排名:今日本吧第个签到,本吧因你更精彩,明天继续来努力!
本吧签到人数:0成为超级会员,使用一键签到本月漏签0次!成为超级会员,赠送8张补签卡连续签到:天&&累计签到:天超级会员单次开通12个月以上,赠送连续签到卡3张
关注:17,931贴子:
Surface3的八种截屏方法--Win10版收藏
Surface3的八种截屏方法--Win10版--by屠龙刀1.同时按下顶部音量减小按钮和右侧Windows徽标虚拟键,屏幕会暗一下,截取全屏,截图保存在“图片--屏幕截图”中,同时暂存于剪切板。2.同时按住键盘上的Windows徽标键和Fn键,再按下空格键,屏幕会暗一下,截取全屏,截图保存在“图片--屏幕截图”中,同时暂存于剪切板。3.按住键盘上的Windows徽标键,再按下PrtScn(F7)键,屏幕会暗一下,截取全屏,截图保存在“图片--屏幕截图”中,同时暂存于剪切板。注意在Fn键指示灯亮着的状态下是不行的。4.按下键盘PrtScn(F7)键,屏幕不会暗一下,截取全屏,截图暂存于剪切板,但不会保存在“图片--屏幕截图”中。注意在Fn键指示灯亮着的状态下是不行的。5.按住键盘上的Alt键,再按下键盘PrtScn(F7)键,屏幕不会暗一下,截取当前活动窗口,截图暂存于剪切板,但不会保存在“图片--屏幕截图”中。注意在Fn键指示灯亮着的状态下是不行的。6.连续按两下SurefacePen顶部的按钮,会打开OneNote并让你绘制截屏区域,也可以单击屏幕右上角“剪辑全部”截取全屏,然后截屏区域会自动粘贴在OneNote中,同时暂存于剪切板。7.打开Windows附件中的“截图工具”,在弹出的截图工具小窗口上单击“新建”,就可以进行截屏了,此工具有任意格式截图、矩形截图、窗口截图、全屏幕截图四种方式可以切换。8.在运行桌面版QQ时,同时按下Ctrl+Alt+A,就可以绘制截屏区域进行截屏了,还可以填写文字、绘制标记等。欢迎加入Surface3技术交流群
上海张学友、王菲演唱会一站式购票!票品安全且真票!立即订购!
总结的很好
第一个最好用
登录百度帐号推荐应用
为兴趣而生,贴吧更懂你。或

我要回帖

更多关于 surface pro 怎么截图 的文章

 

随机推荐