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

//相册获取
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);



  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值