还有另一种方法我应该这样做吗?或者我在代码中遗漏了什么?
谢谢!
-(UIImage *) createScreenShotthumbnailWithWIDth:(CGfloat)wIDth{ // Size of our VIEw CGSize size = editorContentVIEw.bounds.size; //First Grab our Screen Shot at Full Resolution UIGraphicsBeginImageContext(size); [editorContentVIEw.layer renderInContext:UIGraphicsGetCurrentContext()]; UIImage *screenShot = UIGraphicsGetimageFromCurrentimageContext(); UIGraphicsEndImageContext(); //Calculate the scal ratio of the image with the wIDth supplIEd. CGfloat ratio = 0; if (size.wIDth > size.height) { ratio = wIDth / size.wIDth; } else { ratio = wIDth / size.height; } //Setup our rect to draw the Screen shot into CGSize newSize = CGSizeMake(ratio * size.wIDth,ratio * size.height); //Send back our screen shot return [self imageWithImage:screenShot scaledToSize:newSize];}解决方法 您是否使用“Time Profiler”工具(“产品”菜单 – >“配置文件”)来检查代码中您花费大部分时间的位置? (当然,使用它与您的设备,而不是模拟器,以实现真实的分析).我猜它不是你在问题中引用的图像捕获部分,而是在你的重新缩放方法imageWithImage:scaledToSize:method中.
不是在上下文中以整个大小渲染图像,而是将图像重新缩放到最终大小,您应该通过对上下文应用一些仿射变换,直接以预期大小渲染上下文中的图层.
所以只需使用CGContextConcatCTM(someScalingAffinetransform);在你的行UIGraphicsBeginImageContext(size);之后的UIGraphicsGetCurrentContext()上,应用缩放仿射变换,这将使图层以不同的比例/大小呈现.
这样它将直接渲染为预期的大小,这将更快,而不是以100%渲染,然后让你以一种耗时的方式重新缩放它
总结以上是内存溢出为你收集整理的ios – 捕获UIView的屏幕截图 – 性能缓慢全部内容,希望文章能够帮你解决ios – 捕获UIView的屏幕截图 – 性能缓慢所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)