iOS camera launch, picture read, store demo

Source: Internet
Author: User

#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-aren ' t in use.
}

#pragma mark-view lifecycle

-(void) viewdidload
{
[Super Viewdidload];
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 class method to determine if the source is available Uiimagepickercontroller is a picture selection controller that can select images in three ways. Camera, Photolibrary, Savedphotoalbum
BOOL Hascamera = [Uiimagepickercontroller issourcetypeavailable:uiimagepickercontrollersourcetypecamera];// Determine if the camera is available (webcam)
if (Hascamera = = YES)
{
Uiimagepickercontroller *picker = [[Uiimagepickercontroller alloc] init];
Picker.sourcetype = Uiimagepickercontrollersourcetypecamera;
Picker.delegate = self;
picker.allowsediting = YES; Whether it can be edited
[Self presentmodalviewcontroller:picker animated:yes];
[Picker release];
}
Else
{
Uialertview *alert = [[Uialertview alloc] initwithtitle:@ "hint" message:@ "you don't have a webcam" 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;

If you want to store a UIImage object in the default album, use the following code
Uiimagewritetosavedphotosalbum (image, nil, nil, nil);


[Self dismissmodalviewcontrolleranimated:yes];

}

-(void) Imagepickercontrollerdidcancel: (Uiimagepickercontroller *) picker
{
[Self dismissmodalviewcontrolleranimated:yes];
}

-(Ibaction) Openphotolibrary: (ID) sender//Album List
{
Uiimagepickercontroller *picker = [[Uiimagepickercontroller alloc] init];
Picker.sourcetype = uiimagepickercontrollersourcetypephotolibrary;
Picker.delegate = self;
picker.allowsediting = YES; Whether it can be edited
[Self presentmodalviewcontroller:picker animated:yes];
[Picker release];
}

-(Ibaction) Opensavedphotoalbum: (ID) sender//default album
{
Uiimagepickercontroller *picker = [[Uiimagepickercontroller alloc] init];
Picker.sourcetype = Uiimagepickercontrollersourcetypesavedphotosalbum;
Picker.delegate = self;
picker.allowsediting = YES; Whether it can be edited
[Self presentmodalviewcontroller:picker animated:yes];
[Picker release];

}
-(void) Dealloc {
[IMGV release];
[Super Dealloc];
}
@end

iOS camera launch, picture read, store demo

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.