加载图片
//点击加载图片按钮
- (IBAction)picture:(id)sender {
UIImagePickerController*picker = [[UIImagePickerControlleralloc]init];
//设置数据源,图片显示的来源是什么,可以是相机、照片薄、或者图片库
picker.sourceType=UIImagePickerControllerSourceTypeSavedPhotosAlbum;
//设置的代理
picker.delegate=self;
// model出相册的控制器的View
[selfpresentViewController:pickeranimated:YEScompletion:nil];
}
//当点击了加载图片按钮之后需要遵守协议
- (void)imagePickerController:(UIImagePickerController*)picker didFinishPickingMediaWithInfo:(NSDictionary*)info{
//这里会加载选中的图片,并将他显示到一个单独的imageView中
//从字典信息中选择保存的图片键值对;
UIImage*image = info[UIImagePickerControllerOriginalImage];
ZHHandleImageView*imagV = [[ZHHandleImageViewalloc]initWithFrame:_drawView.bounds];
imagV.image= image;
[_drawViewaddSubview:imagV];
// dismiss modle出的控制器(退出照片选择器)
[pickerdismissViewControllerAnimated:YEScompletion:nil];
}
读取图片
- (IBAction)save:(id)sender {
//截图,并保存到相册中,
UIImageWriteToSavedPhotosAlbum([UIImagecaptureWithView:_drawView],self,@selector(image:didFinishSavingWithError:contextInfo:),nil);
}
//点击保存按钮之后的提示,这是系统推荐的必须实现的方法,没有提示,只能从写入相册的提示中找
- (void)image:(UIImage*)image didFinishSavingWithError:(NSError*)error contextInfo: (void*)contextInfo{
if(error) {
[MBProgressHUDshowError:@"保存失败"];
}else{
[MBProgressHUDshowSuccess:@"保存成功"];
}
}
iOS技术成长群:255032637 有愿意的小伙伴可以长期学习共勉!