//
// 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 获取用户相册。保存图片。编辑图片为圆形的更多相关文章

  1. app保存图片到用户相册时闪退解决办法

    在iOS11中,app保存图片到用户相册时必须添加权限使用描述即NSPhotoLibraryAddUsageDescription,否则会闪退. 只需在info.plist—Property List ...

  2. 2019-9-2-win10-uwp-截图-获取屏幕显示界面保存图片

    title author date CreateTime categories win10 uwp 截图 获取屏幕显示界面保存图片 lindexi 2019-09-02 12:57:38 +0800 ...

  3. ***微信公众平台开发: 获取用户基本信息+OAuth2.0网页授权

    本文介绍如何获得微信公众平台关注用户的基本信息,包括昵称.头像.性别.国家.省份.城市.语言.本文的方法将囊括订阅号和服务号以及自定义菜单各种场景,无论是否有高级接口权限,都有办法来获得用户基本信息, ...

  4. 【转】【Android应用开发详解】第01期:第三方授权认证(一)实现第三方授权登录、分享以及获取用户资料

    转载请注明出处:http://blog.csdn.net/yangyu20121224/article/details/9057257 由于公司项目的需要,要实现在项目中使用第三方授权登录以及分享文字 ...

  5. iOS获取用户设备崩溃日志并分析

    项目最近发布,部分用户在内侧使用,正好遇到一些问题,由于用户在其他城市,所以对于用户设备产生的崩溃日志,不好直接拿设备连接电脑. 对于这种情况,我们可以这样: 1.引导用户开启iOS设备设置-> ...

  6. 小程序登录&授权&获取用户信息

    一 .登录 时序图如下: wx.login() 获取js_code 示例代码: App({   onLaunch: function() {     wx.login({       success: ...

  7. Python学习---Django的request扩展[获取用户设备信息]

    关于Django的request扩展[获取用户设备信息] settings.py INSTALLED_APPS = [ ... 'app01', # 注册app ] STATICFILES_DIRS ...

  8. 【Android应用开发详解】实现第三方授权登录、分享以及获取用户资料

      由于公司项目的需要,要实现在项目中使用第三方授权登录以及分享文字和图片等这样的效果,几经波折,查阅了一番资料,做了一个Demo.实现起来的效果还是不错的,不敢独享,决定写一个总结的教程,供大家互相 ...

  9. Android之QQ授权登录获取用户信息

    有时候我们开发的app须要方便用户简单登录.能够让用户使用自己的qq.微信.微博登录到我们自己开发的app. 今天就在这里总结一下怎样在自己的app中集成QQ授权登录获取用户信息的功能. 首先我们打开 ...

随机推荐

  1. [.NET] [.net 脱壳工具]Sixxpack 最新脱壳机 通杀Sixxpack全版本by -=Msdn5 君临=

    [.net 脱壳工具]Sixxpack 最新脱壳机 通杀Sixxpack全版本by -=Msdn5 君临=- 识别方法: 如果无法调戏,请上传附件艾特我.............发帖不易啊..身处大西 ...

  2. 使用Axure RP原型设计实践01,使用概述

    首先认识Axure RP Pro 7.0软件的默认界面布局.最上面的是工具栏区域,左侧上方的是网站地图区域(sitemap),左侧中部的是部件区域(Widgets),左侧下方的是模板区域(Master ...

  3. delphi中单独编译pas生成dcu文件

    delphi中单独编译pas生成dcu文件 在网上下载了一个带源码的组件,结果碰到提示说缺少xxx.dcu.一看它的目录下确实没有,那能不能生成一个呢? 当然可以! 方法是使用delphi的安装目录\ ...

  4. Delphi把一张PNG横向分割成N张透明通道的图片

    Delphi新版本虽然集成了PngImage但是分割复制什么的却非常难用.稍微封装了一下.可以把一张PNG横向分割成N张.透明通道什么的都可以保持不变.typeTPngArray = array of ...

  5. UIScrollView的判断位置的属性如下:

    contentSize:CGSize类型,scrollview可以滑动的区域,例如,一个view的frame为(0,0,320,480),而scrollview的contentSize为(320,10 ...

  6. 【linux】find命令仅返回文件名 不用返回完整的文件路径

    正常查询 find /apps/swapping -name '*swapping*.jar' 在/apps/swapping 目录下 查找 文件名为 '包含swapping的并且以.java结尾的文 ...

  7. android Installation error: INSTALL_FAILED_VERSION_DOWNGRADE

    http://www.apkbus.com/android-114019-1-1.html   提高 AndroidManifest.xml中的manifest的android:versionCode ...

  8. 三层架构下实现用户登陆C#

    上篇文章讲到三层.接下来就通过一个实例详细的看怎么用三层实现用户登陆界面. 一.Model实体(LoginModel): namespace LoginModel { //加入类:UserInfo M ...

  9. 黑吃黑第一季/全集Banshee迅雷下载

    第一季 Banshee Season 1 (2013)看点:“Banshee”在爱尔兰盖尔语中被称为“bean sidhe”,意思是“拥有超能力的女人”.不过在鲍尔的新剧中,Banshee并不是指超自 ...

  10. An internal error occurred during: "Building workspace". GC overhead limit exceeded

    1 错误描写叙述 2 错误原因 3 解决的方法