您的位置:首页 > 移动开发 > IOS开发

IOS程序访问iPhone手机相册/相机来获取图片的方法

2013-03-21 17:04 711 查看
//相册获取
if(buttonIndex==0)
{
//确定当前所指向的图片源是否存在
if([UIImagePickerControllerisSourceTypeAvailable:UIImagePickerControllerSourceTypePhotoLibrary])
{
//相册获取,将获取到的图片放入ImagePicker里面
self.imagePicker.sourceType=UIImagePickerControllerSourceTypePhotoLibrary;
}
}
//相机获取图片
if(buttonIndex==1)
{
if([UIImagePickerControllerisSourceTypeAvailable:UIImagePickerControllerSourceTypeCamera])
{
//相机获取图片
self.imagePicker.sourceType=UIImagePickerControllerSourceTypeCamera;
}
}
//可以编辑图像,选定图片在指定方框内,进行剪切处理
self.imagePicker.allowsEditing=YES;
[self presentModalViewController:self.imagePickeranimated:YES];
 
IOS获取手机闪光灯的操作
iPHONE获取手机闪光灯对象,制作手电筒工具
需要运入对象AVFoundation.Framework,因为闪光灯也属于多媒体设备,所以需要引入这个框架
AVCaptureDevice *device=[AVCaptureDevicedefaultDeviceWithMediaType:AVMediaTypeVideo];
NSError *error = nil;
//检测该设备是否提供闪光灯功能
if([device hasTorch])
{
//与后者Unlock是成对的API,两者之间提供对闪光灯的控制
BOOL locked = [device lockForConfiguration:&error];
if(locked)
{
if(!ifLight)
{
bgImage.image=[UIImageimageNamed:@"bgon.png"];
[switchButton setImage:[UIImage imageNamed:@"on.png"] forState:UIControlStateNormal];
ifLight=YES;
//开灯操作
device.torchMode =AVCaptureFlashModeOn;
}
else
{
bgImage.image=[UIImageimageNamed:@"bgoff.png"];
[switchButton setImage:[UIImage imageNamed:@"off.png"] forState:UIControlStateNormal];
ifLight=NO;
//关灯操作
device.torchMode =AVCaptureTorchModeOff;
}
}
[device unlockForConfiguration];
}

//将当前View里面的Image保存到相册
#import<QuartzCore/QuartzCore.h>

要响应的方法里面添加:
UIGraphicsBeginImageContext(currentView.bounds.size);     //currentView 当前的view

[currentView.layerrenderInContext:UIGraphicsGetCurrentContext()];

UIImage *viewImage =UIGraphicsGetImageFromCurrentImageContext();

UIGraphicsEndImageContext();

UIImageWriteToSavedPhotosAlbum(viewImage,nil, nil, nil);
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
相关文章推荐