//
// 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. ASP.NET Web API基于OData的增删改查,以及处理实体间关系

    本篇体验实现ASP.NET Web API基于OData的增删改查,以及处理实体间的关系. 首先是比较典型的一对多关系,Supplier和Product. public class Product { ...

  2. Unity3D实践系列02,查看Scene窗口物体

    删除"Hierarchy"窗口中的"Directional Light". 把鼠标放在"Scene"窗口,滑动鼠标滚轮,可以对"S ...

  3. Android App组件之Activity

    Android App组件之Activity 1 activit介绍 Activities 是Android的四大组件之一,其余三大组件是service.broadcast和content provi ...

  4. 【推荐】腾讯android镜像(做Android开发的得好好利用下这个网站,国内的大公司还是可以滴……)

    原文地址:http://android-mirror.bugly.qq.com:8080/include/usage.html ☀ Windows I. Open Android SDK Manage ...

  5. .NET:注意 Primitive 这个小坑

    背景 有个需求,需要递归遍历类型的所有属性(属性的属性),然后对不同的类型做不同的处理,或者只是将类型分为三类:Primitive.Complex 和 Collection.因为 MS 的 Type ...

  6. 关于面试总结1-SQL学生表

    前言 每次面试必考SQL,小编这几年一直吃SQ的亏,考题无非就是万年不变学生表,看起来虽然简单,真正写出来,还是有一定难度.于是决定重新整理下关于SQL的面试题,也可以帮助更多的人过SQL这一关. 作 ...

  7. 新闻编辑室第一季/全集The Newsroom迅雷下载

    第一季 The Newsroom Season 1 (2012)看点:频出佳剧的HBO这次将目光对准了新闻间这个话题多,故事更多的“小”地方.该剧讲述的是一家虚构的有线电视新闻网ACN的故事,由阿伦· ...

  8. SimpleAdapter和AutoCompleteTextView配合使用

     修改后成为这样→    package com.kale.autocompletetextview; import java.util.ArrayList; import java.util.Has ...

  9. Eclipse启动时提示fail to create the Java Virtual Machine问题的解决办法

    是eclipse.ini文件的问题,打开eclipse安装目录下的eclipse.ini文件: 将其中的256m改为128m,512m改为256m,1024m改为512m即可 修改后如下: -star ...

  10. .NET零基础入门10:打老鼠之数据存储

    一:数据库设计 到此为止,打老鼠游戏还不能保存每次游戏的成绩,我们今天完成的任务就是要存储成绩到SQLSERVER的数据库中. 在上节课中,我们已经知道了如何创建数据库,所有,先创建数据库" ...