ios如何获取相册中的图片

-(void)themBtnClick//访问相册的按钮的方法

{

UIImagePickerController *pickerImage = [[UIImagePickerController alloc] init];

if([UIImagePickerController isSourceTypeAvailable:UIImagePickerControllerSourceTypeSavedPhotosAlbum]) {

pickerImage.sourceType = UIImagePickerControllerSourceTypeSavedPhotosAlbum;

//pickerImage.sourceType = UIImagePickerControllerSourceTypeSavedPhotosAlbum;

pickerImage.mediaTypes = [UIImagePickerController availableMediaTypesForSourceType:pickerImage.sourceType];

}

pickerImage.delegate = self;

pickerImage.allowsEditing = YES;

[self presentViewController:pickerImage animated:YES completion:nil];

}

/*-----------------------------UIImagePickerController的代理方法------------------------------------*/

- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info{

UIImage *image=[info objectForKey:UIImagePickerControllerEditedImage];

UIImage *theImage = [self imageWithImageSimple:image scaledToSize:CGSizeMake(250.0, 167.0)];

//        _themeImg.image = theImage;

_themeImg.image = theImage;

[self dismissViewControllerAnimated:YES completion:^{

}];

}

- (UIImage*)imageWithImageSimple:(UIImage*)image scaledToSize:(CGSize)newSize

{//

// Create a graphics image context

UIGraphicsBeginImageContext(newSize);

// Tell the old image to draw in this new context, with the desired

// new size

[image drawInRect:CGRectMake(0,0,newSize.width,newSize.height)];

// Get the new image from the context

UIImage* newImage = UIGraphicsGetImageFromCurrentImageContext();

// End the context

UIGraphicsEndImageContext();

// Return the new image.

return newImage;

}

最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容

  • 提到从摄像头/相册获取图片是面向终端用户的,由用户去浏览并选择图片为程序使用。在这里,我们需要过UIImagePi...
    Ashoka_APP阅读 1,531评论 1 1
  • { 11、核心动画 需要签协议,但是系统帮签好 一、CABasicAnimation 1、创建基础动画对象 CAB...
    CYC666阅读 1,591评论 2 4
  • 原文链接http://www.cnblogs.com/kenshincui/p/4186022.html 音频在i...
    Hyman0819阅读 21,826评论 4 74
  • 音节就是这个音标里有几个元音就有几个音节。单音节都重读。 双音节前重读读汉语的平音,后重读读汉语的第四音。 多音节...
    小绿植物阅读 171评论 0 0
  • 事件:分为两部分 1、行为本身:浏览器天生就赋予其的行为:onmouseover(onmouserenter)、o...
    gaoqizhuhui阅读 305评论 0 0