OS 获取用户相册。保存图片。编辑图片为圆形
//
// ViewController.m
// YunPhoto
//
// Created by qingyun on 3/4/14.
// Copyright (c) 2014 qingyun. All rights reserved.
// #import "ViewController.h" @interface ViewController () @end @implementation ViewController
@synthesize sheet; - (void)viewDidLoad
{
[super viewDidLoad]; UIButton *selectBtn = [[UIButton alloc]init];
selectBtn.frame = CGRectMake(, , , );
[selectBtn addTarget:self action:@selector(UserImageClicked) forControlEvents:UIControlEventTouchUpInside];
[self.view addSubview:selectBtn]; UILabel *selectLabel = [[UILabel alloc]init];
selectLabel.frame = CGRectMake(, , , );
selectLabel.text = @"chose";
selectLabel.textColor = [UIColor redColor];
[selectBtn addSubview:selectLabel]; imageView = [[UIImageView alloc]init];
imageView.frame = CGRectMake(, , , );
[self.view addSubview:imageView];
//imageView.layer.masksToBounds = YES;
//imageView.layer.cornerRadius = 160; UIButton *saveBtn = [[UIButton alloc]init];
saveBtn.frame = CGRectMake(, , , );
[saveBtn addTarget:self action:@selector(saveImgBtnPress) forControlEvents:UIControlEventTouchUpInside];
[self.view addSubview:saveBtn]; UILabel *saveLabel = [[UILabel alloc]init];
saveLabel.frame = CGRectMake(, , , );
saveLabel.text = @"save";
saveLabel.textColor = [UIColor redColor];
[saveBtn addSubview:saveLabel]; // Do any additional setup after loading the view, typically from a nib.
} - (void)didReceiveMemoryWarning
{
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
} - (void)UserImageClicked
{ // 判断是否支持相机
if([UIImagePickerController isSourceTypeAvailable:UIImagePickerControllerSourceTypeCamera])
{
self.sheet = [[UIActionSheet alloc] initWithTitle:@"选择图像" delegate:self cancelButtonTitle:nil destructiveButtonTitle:@"取消" otherButtonTitles:@"拍照", @"从相册选择", nil];
}
else {
self.sheet = [[UIActionSheet alloc] initWithTitle:@"选择图像" delegate:self cancelButtonTitle:nil destructiveButtonTitle:@"取消" otherButtonTitles:@"从相册选择", nil];
} self.sheet.tag = ;
//[self.sheet showInView:self.view]; UIWindow* window = [[[UIApplication sharedApplication] delegate] window];
if ([window.subviews containsObject:self.view]) {
[self.sheet showInView:self.view];
} else {
[self.sheet showInView:window];
}
} - (void)actionSheet:(UIActionSheet *)actionSheet clickedButtonAtIndex:(NSInteger)buttonIndex
{
if (actionSheet.tag == ) {
NSUInteger sourceType = UIImagePickerControllerSourceTypePhotoLibrary;
// 判断是否支持相机
if([UIImagePickerController isSourceTypeAvailable:UIImagePickerControllerSourceTypeCamera]) {
switch (buttonIndex) {
case :
return;
case : //相机
sourceType = UIImagePickerControllerSourceTypeCamera;
break;
case : //相册
sourceType = UIImagePickerControllerSourceTypePhotoLibrary;
break;
}
}
else {
if (buttonIndex == ) {
return;
} else {
sourceType = UIImagePickerControllerSourceTypeSavedPhotosAlbum;
}
}
// 跳转到相机或相册页面
UIImagePickerController *imagePickerController = [[UIImagePickerController alloc] init];
imagePickerController.delegate = self;
imagePickerController.allowsEditing = YES;
imagePickerController.sourceType = sourceType; [self presentViewController:imagePickerController animated:YES completion:^{}];
}
} #pragma mark - image picker delegte
- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info
{
[picker dismissViewControllerAnimated:YES completion:^{}]; UIImage *img = [info objectForKey:@"UIImagePickerControllerOriginalImage"]; imageView.image = [self circleImage:img withParam:];
//保存图片 savedImage = imageView.image; //
// NSData *imageData = UIImageJPEGRepresentation(image, COMPRESSED_RATE);
// UIImage *compressedImage = [UIImage imageWithData:imageData];
//
// [HttpRequestManager uploadImage:compressedImage httpClient:self.httpClient delegate:self]; } //圆形的图片
-(UIImage*) circleImage:(UIImage*) image withParam:(CGFloat) inset {
UIGraphicsBeginImageContext(image.size);
CGContextRef context = UIGraphicsGetCurrentContext();
CGContextSetLineWidth(context,); //边框线
CGContextSetStrokeColorWithColor(context, [UIColor redColor].CGColor);
CGRect rect = CGRectMake(inset, inset, image.size.width - inset * 2.0f, image.size.height - inset * 2.0f);
CGContextAddEllipseInRect(context, rect);
CGContextClip(context); [image drawInRect:rect];
CGContextAddEllipseInRect(context, rect);
CGContextStrokePath(context);
UIImage *newimg = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
return newimg;
} -(void)saveImgBtnPress
{
[self saveImageToPhotos:savedImage];
} - (void)saveImageToPhotos:(UIImage*)savedImage
{
if(imageView.image)
{
UIImageWriteToSavedPhotosAlbum(imageView.image, self, @selector(image:didFinishSavingWithError:contextInfo:), NULL);
}
}
// 指定回调方法
- (void)image: (UIImage *) image didFinishSavingWithError: (NSError *) error contextInfo: (void *) contextInfo
{
NSString *msg = nil ;
if(error != NULL){
msg = @"保存图片失败" ;
}else{
msg = @"保存图片成功" ;
}
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"保存图片结果提示"
message:msg
delegate:self
cancelButtonTitle:@"确定"
otherButtonTitles:nil];
[alert show];
} // 调用示例 @end
demo 下载地址:https://github.com/qingjoin/iOSPhotoProject
OS 获取用户相册。保存图片。编辑图片为圆形的更多相关文章
- app保存图片到用户相册时闪退解决办法
在iOS11中,app保存图片到用户相册时必须添加权限使用描述即NSPhotoLibraryAddUsageDescription,否则会闪退. 只需在info.plist—Property List ...
- 2019-9-2-win10-uwp-截图-获取屏幕显示界面保存图片
title author date CreateTime categories win10 uwp 截图 获取屏幕显示界面保存图片 lindexi 2019-09-02 12:57:38 +0800 ...
- ***微信公众平台开发: 获取用户基本信息+OAuth2.0网页授权
本文介绍如何获得微信公众平台关注用户的基本信息,包括昵称.头像.性别.国家.省份.城市.语言.本文的方法将囊括订阅号和服务号以及自定义菜单各种场景,无论是否有高级接口权限,都有办法来获得用户基本信息, ...
- 【转】【Android应用开发详解】第01期:第三方授权认证(一)实现第三方授权登录、分享以及获取用户资料
转载请注明出处:http://blog.csdn.net/yangyu20121224/article/details/9057257 由于公司项目的需要,要实现在项目中使用第三方授权登录以及分享文字 ...
- iOS获取用户设备崩溃日志并分析
项目最近发布,部分用户在内侧使用,正好遇到一些问题,由于用户在其他城市,所以对于用户设备产生的崩溃日志,不好直接拿设备连接电脑. 对于这种情况,我们可以这样: 1.引导用户开启iOS设备设置-> ...
- 小程序登录&授权&获取用户信息
一 .登录 时序图如下: wx.login() 获取js_code 示例代码: App({ onLaunch: function() { wx.login({ success: ...
- Python学习---Django的request扩展[获取用户设备信息]
关于Django的request扩展[获取用户设备信息] settings.py INSTALLED_APPS = [ ... 'app01', # 注册app ] STATICFILES_DIRS ...
- 【Android应用开发详解】实现第三方授权登录、分享以及获取用户资料
由于公司项目的需要,要实现在项目中使用第三方授权登录以及分享文字和图片等这样的效果,几经波折,查阅了一番资料,做了一个Demo.实现起来的效果还是不错的,不敢独享,决定写一个总结的教程,供大家互相 ...
- Android之QQ授权登录获取用户信息
有时候我们开发的app须要方便用户简单登录.能够让用户使用自己的qq.微信.微博登录到我们自己开发的app. 今天就在这里总结一下怎样在自己的app中集成QQ授权登录获取用户信息的功能. 首先我们打开 ...
随机推荐
- 得到WAV文件的长度
long getVideoLength (char *fileName){ MCI_OPEN_PARMS mciOpenParms; MCI_STATUS_PARMS mciStatusPar ...
- C#学习笔记:预处理指令
C#和C/C++一样,也支持预处理指令,下面我们来看看C#中的预处理指令. #region 代码折叠功能,配合#endregion使用,如下: 点击后如下: 条件预处理 条件预处理可以根据给出的条件决 ...
- java单例模式实例
什么是单例模式? 定义:确保一个类只有一个实例,而且自行实例化并向整个系统提供这个实例场景,也就是说:确保某个类有且只有一个对象的场景,避免产生多个对象消耗过多的资源,或者某种类型的对象应该有且只有一 ...
- linux 7z 命令编译安装,mac安装p7zip
linux 7z 命令编译安装 7zip是一个开源的压缩软件 7z格式是压缩率最高的格式 服务器备份 数据几个g 要是tar压缩下载的话 时间太长 7zip压缩出来体积很小 首先安装 我这是 ce ...
- Asp.Net Core 静态文件目录操作
一.默认静态文件处理 Asp.Net Core的默认处理方式,将所有的静态文件都放在wwwroot文件夹中 1.默认配置,在启动文件Startup中 public void Configure(IAp ...
- 使用ASP.NET读取word2003文档
直接使用.NET 读取doc文档. http://www.codeproject.com/Articles/22738/Read-Document-Text-Directly-from-Microso ...
- Jackcess 1.2.13 发布,Java 访问 Access 数据库
Jackcess 1.2.13 包含新的方法用于在数据库和附件内容解码中查找复杂值类型的关系,修复了 CodeHandler 相关的一些小 bug. Jackcess 是一个Java 类库,用来读写微 ...
- Linux修改终端显示前缀及环境变量
Linux终端前面默认显示一长串,如: [work@aaa.baidu.com dir]$ 这是由PS1环境变量决定的: [work@aaa.baidu.com dir]$ echo $PS1 [\u ...
- Spring系列:Scheduled注解学习笔记
一.试验代码 //@Scheduled(fixedRate = 5000) //@Scheduled(fixedDelay = 5000) @Scheduled(cron ="*/5 * * ...
- System.Diagnostics.Debug和System.Diagnostics.Trace
在 .net 类库中有一个 system.diagnostics 命名空间,该命名空间提供了一些与系统进程.事件日志.和性能计数器进行交互的类库.当中包括了两个对开发人员而言十分有用的类——debug ...