Swift实现截屏并保存相册

 func saveToLocal() {
        //截屏
        let screenRect = UIScreen.mainScreen().bounds
        UIGraphicsBeginImageContext(screenRect.size)
        let ctx:CGContextRef = UIGraphicsGetCurrentContext()!
        self.view.layer.renderInContext(ctx)
        let image = UIGraphicsGetImageFromCurrentImageContext()
        UIGraphicsEndImageContext();

        //保存相册
        UIImageWriteToSavedPhotosAlbum(image!, self, "image:didFinishSavingWithError:contextInfo:", nil)

    }

    func image(image:UIImage,didFinishSavingWithError error:NSError?,contextInfo:AnyObject) {

        if error != nil {
            K12ProgressHUD.showError("保存失败", view: self.view)
        } else {
            K12ProgressHUD.showSucess("保存成功", view: self.view)
        }
    }

  

时间: 2024-07-30 20:07:38

Swift实现截屏并保存相册的相关文章

Qt实现截屏并保存(转载)

原博地址:http://blog.csdn.net/qinchunwuhui/article/details/52869451?_t_t_t=0.28889142944202306 目前对应用实现截屏的方法还是比较多的,首先我们要了解Qt中的窗口的是如何设计的,不管是MFC下的窗口,还是其他窗口,仿佛都相似,曾经狂学MFC,结果毕业一次没用过已经还给老师,悲催,好了下面我们来介绍一下Qt的窗口设计吧!鸡冻吧-. 1.首先我们来看看我从手册上盗取的图片  我们了解了Qt的窗口框架,让我们来看看她(

android 关于截屏保存图片到相册功能

iv_photo.buildDrawingCache(); iv_photo.setBackgroundColor(mContext.getResources().getColor(R.color.TextColorWhite)); iv_photo.setDrawingCacheEnabled(true); Bitmap bitmap = iv_photo.getDrawingCache(); SimpleDateFormat formatter = new SimpleDateFormat(

android-实现手机截屏效果,保存截屏图片

一.准备一张图片 拷贝screenshot_panel.9.png放在目录drawable-xhdpi下 二.activity_main.xml 代码如下: <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools" android:layout_width="matc

iOS截屏保存至相册

#pragma mark 截屏并保存至相册 -(void)screenShotsComplete:(void(^)(UIImage * img)) complete { CGSize imageSize = [[UIScreen mainScreen] bounds].size; UIGraphicsBeginImageContextWithOptions(imageSize, NO, 0); CGContextRef context = UIGraphicsGetCurrentContext(

iOS中的截屏(屏幕截屏及scrollView或tableView的全部截屏)

iOS中的截屏(屏幕截屏及scrollView或tableView的全部截屏) 2017.03.16 12:18* 字数 52 阅读 563评论 4喜欢 2 1. 截取屏幕尺寸大小的图片并保存至相册 保存至相册只需将方法saveImage中的代码替换即可 UIGraphicsBeginImageContextWithOptions(self.view.bounds.size, YES, 0.0); [self.view.layer renderInContext:UIGraphicsGetCur

iOS开发--截屏

- (void)snapshotScreen:(UIView *)myView {    CGSize size = myView.bounds.size;    UIGraphicsBeginImageContextWithOptions(size, NO, [UIScreen mainScreen].scale);    CGRect rect = myView.frame;    //  自iOS7开始,UIView类提供了一个方法-drawViewHierarchyInRect:afte

12.3、Libgdx的图像之截屏

(官网:www.libgdx.cn) 接下来的示例说明怎样进行截屏并且保存为PNG格式. public class ScreenshotFactory { private static int counter = 1; public static void saveScreenshot(){ try{ FileHandle fh; do{ fh = new FileHandle("screenshot" + counter++ + ".png"); }while (

robotFramework——截屏

测试执行过程中进行截屏并且保存,是任何一款自动化测试工具或者框架必备的功能.那么Robotframework如何进行截屏呢?Robotframework提供了一个“Screenshot”库.    使用“Screenshot”库前,需要确认window环境中是否已经安装以下软件:        wxPython (地址 http://wxpython.org)               Python Imaging Library (PIL) (地址 http://www.pythonware

使用selenium截屏获取验证码

self.driver = Chrome(CHROME_DRIVER) #初始化对象self.driver.set_window_size(1280, 1024) #设置窗口大小 self.driver.execute_script( 'localStorage.setItem("pre_appadmin_login_2541044284@qq.com",JSON.stringify(%s))' % self.local_storage)#设置localStorage本地缓存 self