多媒体之摄像头、相册

网络这块要学的东西还有好多,比如套接字等,目前只是了解了AFNetworking。掌握了它对网络这块基本功能都可以实现,问题不大,等有机会再深入学习网络这块。目前先把IOS的整体模块都了解学习遍,针对特别的一些模块随后仔细深入理解。现在来看下多媒体这块。

//
//  ViewController.m
//  Photo
//
//  Created by City--Online on 15/5/4.
//  Copyright (c) 2015年 CYW. All rights reserved.
//

#import "ViewController.h"
#import <MobileCoreServices/MobileCoreServices.h>

@interface ViewController ()<UIImagePickerControllerDelegate,UINavigationControllerDelegate,UIActionSheetDelegate>
@property(nonatomic,strong)UIImageView *ImgView;
@end

@implementation ViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    self.navigationItem.title=@"我的相册";
    self.navigationItem.rightBarButtonItem=[[UIBarButtonItem alloc]initWithTitle:@"拍照" style:UIBarButtonItemStyleDone target:self action:@selector(pickerImg)];
    self.navigationController.navigationBar.translucent=NO;
    self.view.backgroundColor=[UIColor redColor];

    self.ImgView=[[UIImageView alloc]initWithFrame:self.view.frame];
    self.ImgView.backgroundColor=[UIColor blueColor];
    [self.view addSubview:self.ImgView];
    [self availableMediaTypes];
    [self availableCaptureModes];
}

-(void)pickerImg
{
    UIImagePickerController *ImgPick=[[UIImagePickerController alloc]init];
    //    typedef NS_ENUM(NSInteger, UIImagePickerControllerSourceType) {
    //        UIImagePickerControllerSourceTypePhotoLibrary, 图片列表
    //        UIImagePickerControllerSourceTypeCamera,       摄像头
    //        UIImagePickerControllerSourceTypeSavedPhotosAlbum 相机相册
    //    };

    ImgPick.sourceType=UIImagePickerControllerSourceTypePhotoLibrary;
    ImgPick.delegate=self;
    //设置当拍照完或在相册选完照片后,是否跳到编辑模式进行图片剪裁。只有当showsCameraControls属性为true时才有效果
    ImgPick.editing=YES;
    //设置拍照时的下方的工具栏是否显示,如果需要自定义拍摄界面,则可把该工具栏隐藏
//    ImgPick.showsCameraControls  = YES;
    //设置使用后置摄像头,可以使用前置摄像头
//    ImgPick.cameraDevice = UIImagePickerControllerCameraDeviceRear;
    //设置闪光灯模式
    /*
     typedef NS_ENUM(NSInteger, UIImagePickerControllerCameraFlashMode) {
     UIImagePickerControllerCameraFlashModeOff  = -1,
     UIImagePickerControllerCameraFlashModeAuto = 0,
     UIImagePickerControllerCameraFlashModeOn   = 1
     };
     */
//    ImgPick.cameraFlashMode = UIImagePickerControllerCameraFlashModeAuto;

    //设置相机支持的类型,拍照和录像
    ImgPick.mediaTypes = @[(NSString*)kUTTypeImage,(NSString*)kUTTypeMovie];
    //叠加View
//    ImgPick.cameraOverlayView=self.view;
    //旋转
//    ImgPick.cameraViewTransform = CGAffineTransformMakeScale(0.5, 0.5);
    //最长时间支持
//    ImgPick.videoMaximumDuration=10;
//    枚举 视频质量
//    ImgPick.videoQuality=UIImagePickerControllerQualityTypeHigh;

//    // 可以通过判断cameraCaptureMode来进行拍照或录像 前提是sourceType=UIImagePickerControllerSourceTypeCamera 上面注释的属性也是
//    if (ImgPick.cameraCaptureMode==UIImagePickerControllerCameraCaptureModePhoto) {
//        [ImgPick takePicture];
//    }
//    else
//    {
//        [ImgPick startVideoCapture];
//        sleep(10);
//        [ImgPick stopVideoCapture];
//    }

    [self presentViewController:ImgPick animated:YES completion:nil];
}

//当选择一张图片后进入这里
-(void)imagePickerController:(UIImagePickerController*)picker didFinishPickingMediaWithInfo:(NSDictionary *)info

{

    NSString *type = [info objectForKey:UIImagePickerControllerMediaType];
    //当选择的类型是图片
    if ([type isEqualToString:@"public.image"])
    {
        //先把图片转成NSData
        UIImage* image = [info objectForKey:@"UIImagePickerControllerOriginalImage"];
        NSData *data;
        if (UIImagePNGRepresentation(image) == nil)
        {
            data = UIImageJPEGRepresentation(image, 1.0);
        }
        else
        {
            data = UIImagePNGRepresentation(image);
        }

        //图片保存的路径
        //这里将图片放在沙盒的documents文件夹中
        NSString * DocumentsPath = [NSHomeDirectory() stringByAppendingPathComponent:@"Documents"];
        //文件管理器
        NSFileManager *fileManager = [NSFileManager defaultManager];
        //把刚刚图片转换的data对象拷贝至沙盒中 并保存为image.png
        [fileManager createDirectoryAtPath:DocumentsPath withIntermediateDirectories:YES attributes:nil error:nil];
        [fileManager createFileAtPath:[DocumentsPath stringByAppendingString:@"/image.png"] contents:data attributes:nil];

        //得到选择后沙盒中图片的完整路径
       NSString *filePath = [[NSString alloc]initWithFormat:@"%@%@",DocumentsPath,  @"/image.png"];
        NSLog(@"%@",filePath);
        //关闭相册界面
        [picker dismissViewControllerAnimated:YES completion:nil];

        //创建一个选择后图片的小图标放在下方
        //类似微薄选择图后的效果
        UIImageView *smallimage = [[UIImageView alloc] initWithFrame:
                                    CGRectMake(50, 120, 100, 100)] ;

        smallimage.image = image;
        //加在视图中
        [self.view addSubview:smallimage];

    }

}

- (void)imagePickerControllerDidCancel:(UIImagePickerController *)picker
{
    NSLog(@"您取消了选择图片");
    [picker dismissViewControllerAnimated:YES completion:nil];
}

//以下这些方法以后可以用到

// 相册是否可用
- (BOOL) isPhotoLibraryAvailable{
    return [UIImagePickerController isSourceTypeAvailable: UIImagePickerControllerSourceTypePhotoLibrary];
}
//是否支持摄像头
-(BOOL)isCameraAvailable
{
    return [UIImagePickerController isSourceTypeAvailable:UIImagePickerControllerSourceTypeCamera];
}
//是否支持前后摄像头
-(BOOL)isFontCameraAvailable
{
    //    typedef NS_ENUM(NSInteger, UIImagePickerControllerCameraDevice) {
    //        UIImagePickerControllerCameraDeviceRear,  后置摄像头
    //        UIImagePickerControllerCameraDeviceFront  前置摄像头
    //    };

    return [UIImagePickerController isCameraDeviceAvailable:UIImagePickerControllerCameraDeviceFront];
}
//是否支持闪光灯、手电筒
-(BOOL)isFlashAvailable
{
    return [UIImagePickerController isFlashAvailableForCameraDevice:UIImagePickerControllerCameraDeviceFront];
}
//支持的媒体类型
-(void)availableMediaTypes
{
    NSArray *array=[UIImagePickerController availableMediaTypesForSourceType:UIImagePickerControllerSourceTypeSavedPhotosAlbum];
    for (NSString* mediaType in array) {
//        (NSString *)kUTTypeImage]) 在MobileCoreServices框架,需要引入并添加#import <MobileCoreServices/MobileCoreServices.h>
        if ([mediaType isEqualToString:(NSString *)kUTTypeImage]) {
            //支持摄像
//            public.image
            NSLog(@"%@",mediaType);
            NSLog(@"支持摄像");
            break;
        }
    }
    NSLog(@"%ld",array.count);
    for (int i=0; i<array.count; i++) {
        NSLog(@"%@",[array objectAtIndex:i]);
    }
}
-(void)availableCaptureModes
{
    //typedef NS_ENUM(NSInteger, UIImagePickerControllerCameraCaptureMode) {
    //    UIImagePickerControllerCameraCaptureModePhoto,
    //    UIImagePickerControllerCameraCaptureModeVideo
    //};
    //支持的相机模式 拍照还是摄像
    NSArray *array=[UIImagePickerController availableCaptureModesForCameraDevice:UIImagePickerControllerCameraDeviceFront];
    NSLog(@"%ld",array.count);
    for (int i=0; i<array.count; i++) {
        NSLog(@"%@",[array objectAtIndex:i]);
    }

}
- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

@end

 

时间: 2024-08-01 11:25:56

多媒体之摄像头、相册的相关文章

ios中摄像头/相册获取图片,压缩图片,上传服务器方法总结

这几天在搞iphone上面一个应用的开发,里面有需要摄像头/相册编程和图片上传的问题,在这里总结一下. [部分知识] iphone中图像通常存储在4个地方[相册.应用程序包.沙盒.Internet],通过这4个源,我们就可以存取应用图片. 相册 iphone的相册包含摄像头胶卷+用户计算机同步的部分照片.用户可以通过UIImagePickerController类提供的交互对话框来从相册中选择图像.但是,注意:相册中的图片机器路径无法直接从应用程序访问,只能通过终端用户去选择和使用相册图片 应用

史上最全的android学习资料

一.开发环境搭建 (已完成) 负责人:kris 状态:已完成 所整理标签为:搭建 SDK JDK NDK Eclipse ADT 模拟器 AVD 调试器(DEBUG) DDMS 测试 日志 Logcat ADB 复制代码 汇总帖子:汇总主帖Android开发环境搭建详尽教程实例 :http://www.eoeandroid.com/thread-165622-1-1.html 分帖: 1. [eoeAndroid社区索引]android开发环境搭建篇详尽的教程实例汇http://www.eoea

手机Web页面 如何调用手机相册 跟 摄像头

问题描述 在做微名片页面,需要手机调用摄像头及手机相册,麻烦告知小弟,不胜感激! 解决方案 解决方案二:这个难实现啊,我知道app中webview嵌入html页面可以调到,但是纯web页面没搞出来,帮顶解决方案三:这个是可以实现的不如你登陆手机QQ进入QQ空间,里面有上传照片的部分.然后用浏览器打开复制地址然后在传到电脑..然后用电脑打开手机网站然后看源码..可能是手机QQ吧反正有一个版本是可以实现的看到过是网页的

PPT2010制作多媒体相册

  PPT里面有新建相册的功能,你有没有尝试过呢.将自己的相片整理成一个有序播放的相册,还可以添加一些游记感想,以后无聊拿出来回味两下也不失为一件乐事啊.下面就跟Word联盟来探索下相册的制作过程吧~ 1.切换到[插入]选项卡,在[图像]选项组,单击[相册]-[新建相册]. 2.在弹出的对话框中单击[文件/磁盘]. 3.弹出对话框中选择相片所在的路径,框选相片,单击[插入]. 4.回到[相册]对话框,图片版式选择[1张图片],相框形状选择[矩形],选择一个主题,需要对相片进行明度,对比度,角度调

IOS多媒体

--iOS多媒体 概览 随着移动互联网的发展,如今的手机早已不是打电话.发短信那么简单了,播放音乐.视频.录音.拍照等都是很常用的功能.在iOS中对于多媒体的支持是非常强大的,无论是音视频播放.录制,还是对麦克风.摄像头的操作都提供了多套API.在今天的文章中将会对这些内容进行一一介绍: 音频 音效 音乐 音频会话 录音 音频队列服务 视频 MPMoviePlayerController MPMoviePlayerViewController AVPlayer 摄像头 UIImagePicker

摄像头不能用的解决方法

一.Win7摄像头不能用 故障现象:摄像头在Windows XP系统下可以正常使用,但换成Windows 7系统后就无法使用了,摄像头本身是无驱动产品,虽然不能用但在系统中却能找到设备.请问这是什么原因? 专家回答:免驱动摄像头,它的芯片中,已经集成了Windows的驱动.如果你的摄像头没有集成Windows 7的驱动,你的摄像头就使用不了. Windows 2000/XP/Vista的驱动,不能用在Windows 7中.解决方法如下: 向厂商索取最新的摄像头芯片固件,如果最新的固件程序支持Wi

摄像头不能用怎么办

1.摄像的速度慢 (摄像头不能用) 故障现象:把刚买回的摄像头安装上网后,感觉显示速度太慢,更换过上网拨号地点和 ISP ,结果速度还是很慢.在不上网时测试这个摄像头,发现这时图像显示也很慢. 分析及处理:这种现象是由于电脑性能过低而引起,可换个图形加速卡,如果还不行,就得升级 CPU 及主板,甚至换台新电脑. 2.摄像头不能和数码相机共用 故障现象:摄像头不能和数码相机一起作输入设备. 分析及处理:有的摄像头带有这种驱动软件, Videofor Windows (即 Windows 视频)及

视频摄像头问题及解答汇总

随着网络视频聊天的热潮侵袭,摄像头已经成为了网民密不可分的工具.不过大家在使用时还是能够遇见一些常见的问题,今天,我们就搜罗了10条比较常见的问题,为大家解答. Q1 我的电脑检测不到摄像头? A:检查操作系统.BIOS.USB接口和安装是否有误. 解决步骤: 第一步:如果您的操作系统是Windows 95,请升级到Windows 98以上,因为Windows95不支持USB接口. 第二步:检查BIOS Setup,使USB装置有效. 如设置正确,还是不能连接摄像头,尝试把摄像头连接到第二个US

Visual C++编程实现摄像头视频捕捉

前言 DirectShow是微软公司提供的一套在Windows平台上进行流媒体处理的开发包,与DirectX开发包一起发布.DirectShow为多媒体流的捕捉和回放提供了强有力的支持.用DirectShow开发应用程序,我们可以很方便地从支持WDM驱动模型的采集卡上捕获数据,并且进行相应的后期处理乃至存储到文件中. DirectShow是基于COM的,为了编写DirectShow应用程序,需要了解COM客户程序编写的基础知识.DirectShow提供了大量的接口,但在编程中发现还是不够方便,如