IOS照相机的启动,图片的读取,存储demo

#import

@interface ViewController : UIViewController
@property (retain, nonatomic) IBOutlet UIImageView *imgV;
- (IBAction)openCamera:(id)sender;

- (IBAction)openPhotoLibrary:(id)sender;

- (IBAction)openSavedPhotoAlbum:(id)sender;

@end

#import "ViewController.h"

@implementation ViewController
@synthesize imgV;

- (void)didReceiveMemoryWarning
{
    [super didReceiveMemoryWarning];
    // Release any cached data, images, etc that aren‘t in use.
}

#pragma mark - View lifecycle

- (void)viewDidLoad
{
    [super viewDidLoad];
    // Do any additional setup after loading the view, typically from a nib.
}

- (void)viewDidUnload
{
    [self setImgV:nil];
    [super viewDidUnload];
    // Release any retained subviews of the main view.
    // e.g. self.myOutlet = nil;
}

- (void)viewWillAppear:(BOOL)animated
{
    [super viewWillAppear:animated];
}

- (void)viewDidAppear:(BOOL)animated
{
    [super viewDidAppear:animated];
}

- (void)viewWillDisappear:(BOOL)animated
{
    [super viewWillDisappear:animated];
}

- (void)viewDidDisappear:(BOOL)animated
{
    [super viewDidDisappear:animated];
}

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
    // Return YES for supported orientations
    return (interfaceOrientation != UIInterfaceOrientationPortraitUpsideDown);
}

- (IBAction)openCamera:(id)sender
{
    //UIImagePickerController 类方法,判断源是否可用 UIImagePickerController是一个图片挑选控制器 可以通过三种途径挑选图片。Camera、PhotoLibrary、SavedPhotoAlbum
    BOOL hasCamera = [UIImagePickerController isSourceTypeAvailable:UIImagePickerControllerSourceTypeCamera];//判断照相机是否可用(是否有摄像头)
    if(hasCamera == YES)
    {
        UIImagePickerController *picker = [[UIImagePickerController alloc] init];
        picker.sourceType = UIImagePickerControllerSourceTypeCamera;
        picker.delegate = self;
        picker.allowsEditing = YES; //是否可编辑
        [self presentModalViewController:picker animated:YES];
        [picker release];
    }
    else
    {
        UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"提示" message:@"你没有摄像头" delegate:nil cancelButtonTitle:@"ok!" otherButtonTitles:nil];
        [alert show];
        [alert release];
    }
   
}

- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info
{
    NSLog(@"%@",info);
//    {
//        UIImagePickerControllerCropRect = "NSRect: {{-1, 320}, {1937, 1937}}";
//        UIImagePickerControllerEditedImage = "";
//        UIImagePickerControllerMediaMetadata =     {
//            DPIHeight = 72;
//            DPIWidth = 72;
//            Orientation = 6;
//            "{Exif}" =         {
//                ApertureValue = "2.970853654340484";
//                BrightnessValue = "2.246098001053075";
//                ColorSpace = 1;
//                DateTimeDigitized = "2012:09:20 11:47:12";
//                DateTimeOriginal = "2012:09:20 11:47:12";
//                ExposureMode = 0;
//                ExposureProgram = 2;
//                ExposureTime = "0.06666666666666667";
//                FNumber = "2.8";
//                Flash = 24;
//                FocalLength = "3.85";
//                ISOSpeedRatings =             (
//                                               125
//                                               );
//                MeteringMode = 5;
//                PixelXDimension = 2592;
//                PixelYDimension = 1936;
//                SceneType = 1;
//                SensingMethod = 2;
//                Sharpness = 2;
//                ShutterSpeedValue = "3.911199862602335";
//                SubjectArea =             (
//                                           1295,
//                                           967,
//                                           699,
//                                           696
//                                           );
//                WhiteBalance = 0;
//            };
//            "{TIFF}" =         {
//                DateTime = "2012:09:20 11:47:12";
//                Make = Apple;
//                Model = "iPhone 4";
//                Software = "5.1.1";
//                XResolution = 72;
//                YResolution = 72;
//            };
//        };
//        UIImagePickerControllerMediaType = "public.image";
//        UIImagePickerControllerOriginalImage = "";
//    }
    UIImage *image = [info objectForKey:@"UIImagePickerControllerOriginalImage"];
    imgV.image = image;
   
    //如果想把某个UIImage对象存储到默认相册,使用下面代码
    //UIImageWriteToSavedPhotosAlbum(image, nil, nil, nil);

[self dismissModalViewControllerAnimated:YES];

}

- (void)imagePickerControllerDidCancel:(UIImagePickerController *)picker
{
    [self dismissModalViewControllerAnimated:YES];
}

- (IBAction)openPhotoLibrary:(id)sender //相册列表
{
    UIImagePickerController *picker = [[UIImagePickerController alloc] init];
    picker.sourceType = UIImagePickerControllerSourceTypePhotoLibrary;
    picker.delegate = self;
    picker.allowsEditing = YES; //是否可编辑
    [self presentModalViewController:picker animated:YES];
    [picker release];
}

- (IBAction)openSavedPhotoAlbum:(id)sender //默认相册
{
    UIImagePickerController *picker = [[UIImagePickerController alloc] init];
    picker.sourceType = UIImagePickerControllerSourceTypeSavedPhotosAlbum;
    picker.delegate = self;
    picker.allowsEditing = YES; //是否可编辑
    [self presentModalViewController:picker animated:YES];
    [picker release];

}
- (void)dealloc {
    [imgV release];
    [super dealloc];
}
@end

时间: 2024-12-13 08:15:40

IOS照相机的启动,图片的读取,存储demo的相关文章

ios替换app启动图片时系统报错的解决办法

ios替换app启动图片时系统报错的解决办法:我个人建议是在开发时候经常行的保存项目,并且在修改项目图标图片.app启动图片前,一定要先备份一份没有添加这两项图片的项目. 如果您的项目已经开发完成了,进入到发布前添加项目图标.app启动图片的时候,一定要确定了这两项的所有图片不会更改了再去添加,否则更改已经添加好的加项目图标.app启动图片就会报错, 如果您报错了,百度之后也没有解决办法,那么就尝试在已经备份的项目中重新去添加图片就可以了.

Ios 应用的启动图片该怎么做

从App Store创建伊始,苹果就一直在推广一个观念:iOS app上架后,它的应用的启动图片(你打开应用第一眼看到的)应该仅仅是一个中间屏幕,仅此而已.引用苹果的人机界面指南如下: "一个启动文件或启动图片的作用是,当应用启动时提供给iOS系统的一个简单的图片占位符.这个图片占位符给用户一个印象:你的应用是快速的.有反应的,因为一点开应用它会立即展现,且很快被应用的第一屏替换." 问题是,相当多的人(包括我自己)忽略了这条准则.如果你对此感到好奇,可以看看上面的封面图,或者把所有运

iOS LaunchScreen设置启动图片并且设置启动页停留时间

当我们想开发一个比较美观的iOS软件时,漂亮的图标和启动图片是必不可少的.一般而言,有两个方法,一个是通过xib文件设置,另一个是通过Assets.xcassets进行设置.但是第二种我没掌握,先把第一种方法记录下来,第二种后面学会再更新. 1.点击项目,把Launch Screen File设置为LaunchScreen 2.点击项目,右键新建文件 3.左侧选择User Interface,选择View,点击next 4.文件名为LaunchScreen 5.建立如下页面 6.把需要设置为启动

iOS LaunchScreen设置启动图片 启动页停留时间

问题:想实现类似微信启动页一样 设置为一个整页面的图片 问题二:iOS启动页面如何设置多停留一会 新建的iOS 项目启动画面默认为LaunchScreen.xib 如果想实现一张图片作为启动页,如下图 如果启动不行  记得clear 一下工程 是启动页停留一段时间  只需要在 AppDelegate - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)laun

iOS LaunchScreen设置启动图片,启动页停留时间

[新建的iOS 项目启动画面默认为LaunchScreen.xib] 如果想实现一张图片作为启动页,如下图 如果启动不行,记得clear 一下工程 如果启动页需要停留一段时间,只需要在 AppDelegate的方法: - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions { // Override point for customiz

iOS程序的启动图片图标规范

IOS 对相册图片进行读取、存储到指定文件夹

这个示例程序主要用到了IOS中的UIImageView.UIImagePickerViewController.UIImage.NSFileManager等知识,结合这些知识构成一个小的应用程序,主要功能是对相册图片进行读取.存储到指定文件夹.从指定文件夹读取出来.这方面的知识在正式项目中用的是比较多的.做Android开发中,经常会使用到将图片保存到SD卡和从SD卡读取图片的操作,相比于Android在这方面的操作,IOS要方便许多. 基本功能是从相册选取一张图片,选完后显示在界面的UIIma

iOS 8 Xcode6 设置Launch Image 启动图片<转>

如何设置App的启动图,也就是Launch Image? Step1 1.点击Image.xcassets 进入图片管理,然后右击,弹出"New Launch Image" 2.如图,右侧的勾选可以让你选择是否要对ipad,横屏,竖屏,以及低版本的ios系统做支持.这边我选了ios8.0,ios7.0,ios6没有做支持. Step2 将规定尺寸的图片从你的文件中拖动进到固定位置. 系统 尺寸 分辨率 ios8 Retina HD5.5 1242x2208   Retina HD4.7

iOS获取app图标和启动图片名字(AppIcon and LaunchImage's name)

在某种场景下,可能我们需要获取app的图标名称和启动图片的名称.比如说app在前台时,收到了远程通知但是通知栏是不会有通知提醒的,这时我想做个模拟通知提示,需要用到icon名称:再比如在加载某个控制器时,想设置该控制器的背景图片为启动图片,需要用到启动图片名称. 而事实上icon图片放在系统AppIcon文件夹里,启动图片放在系统LaunchImage文件夹里,取这些图片的名称和其他一般资源图片名称不一样. 为了方便举例子,咱们先简单粗暴点 假设当前项目只支持iPhone设备,并且只支持竖屏:而