//
// 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. SpringBoot集成JWT实现token验证

    原文:https://www.jianshu.com/p/e88d3f8151db JWT官网: https://jwt.io/ JWT(Java版)的github地址:https://github. ...

  2. android 读取 raw 中的文件。

    file.getParentFile().mkdir(); file.createNewFile(); InputStream inputStream = context.getResources() ...

  3. WordPress主题开发:WP_Query常用参数

    常用参数 用途 调用文章或页面 s 查询和某个关键词相关的所有的文章/页面信息 p 文章或页面id post__in 多篇id post__not_in 多篇id以外 post_type 查询的信息类 ...

  4. c++ 实现atoi()函数

    1. 问题描写叙述 实现c++函数库中atoi()函数,要考虑到各种特殊情况: 空字符串. +和-号. 字符串前中后n个空格. 溢出. 非数字字符. 2. 解决方式 转换过程并不复杂.复杂的是要考虑到 ...

  5. 为什么不能用memcached存储Session

    Memcached创建者Dormando很早就写过两篇文章[1][2], 告诫开发人员不要用memcached存储Session.他在第一篇文章中给出的理由大致是说,如果用memcached存储Ses ...

  6. Cannot convert type SomeClass to 'T'

    以下代码会出问题: public static T Protect<T>(Func<T> func, UserLevel pageRole) where T : ActionR ...

  7. Invalid Host header 的解决方案

    composer 显示:Invalid Host header的解决方案 I have tried this workaround: Edit the following line in node_m ...

  8. 利用rest-framework实现django应用的分页功能

    自定义分页的类,继承 PageNumberPagination class StandardResultsSetPagination(PageNumberPagination): page_size ...

  9. Java SPI(Service Provider Interface)简介

    SPI 简介 SPI 全称为(Service Provider Interface),是JDK内置的一种服务提供发现机制. 一个服务(Service)通常指的是已知的接口或者抽象类,服务提供方就是对这 ...

  10. QT入门系列(3):控制台输出QString

    方式一:使用qDebug()输出 QString str("liyifeng");qDebug() << str;12输出结果:"liyifeng" ...