您的位置:首页 > 移动开发 > IOS开发

iOS 画图 截图

2015-06-29 16:51 435 查看
//

// ViewController.m

// touchSCHEvent

//

// Created by tianshangrenjian on 15/6/29.

// Copyright (c) 2015年 tianshangrenjian. All rights reserved.

//

#import "ViewController.h"

#import "SCHView.h"

@interface
ViewController ()

@property (weak,
nonatomic) IBOutlet
SCHView *schView;
- (IBAction)clearPic:(id)sender;

@end

@implementation ViewController

- (void)viewDidLoad {

[super
viewDidLoad];

// Do any additional setup after loading the view, typically from a nib.

UIImagePickerController *vc;

vc.sourceType=UIImagePickerControllerSourceTypePhotoLibrary;

vc.cameraCaptureMode=UIImagePickerControllerCameraCaptureModePhoto;
}

- (void)didReceiveMemoryWarning {

[super
didReceiveMemoryWarning];

// Dispose of any resources that can be recreated.
}

/*

鼠标点击的时候触发产生的事件

*/
- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event
{

}
//如果要截屏用self.view即可
- (IBAction)savepic:(id)sender {

dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(2
* NSEC_PER_SEC)),
dispatch_get_main_queue(), ^{

UIGraphicsBeginImageContext(
self.schView.frame.size);//尺寸

CGContextRef ctx=UIGraphicsGetCurrentContext();

[self.view.layer
renderInContext:ctx];//图像层

UIImage *img=UIGraphicsGetImageFromCurrentImageContext();

UIImageWriteToSavedPhotosAlbum(img,
nil,
nil, nil);

UIGraphicsEndImageContext();

});

}
- (IBAction)undopic:(id)sender {
[self.schView
undo];
}
- (IBAction)clearPic:(id)sender {
[self.schView
clear];
}

@end
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: