IOS Camera Features

Source: Internet
Author: User

1. Turn on the camera

-(Ibaction) Open: (ID) Sender {

Uiimagepickercontroller *picker = [[Uiimagepickercontroller alloc] init];

if ([Uiimagepickercontrollerissourcetypeavailable:uiimagepickercontrollersourcetypecamera]) {

Picker.sourcetype = Uiimagepickercontrollersourcetypecamera;

Nsarray *temp_mediatypes = [UIImagePickerControlleravailableMediaTypesForSourceType:picker.sourceType];

Picker.mediatypes = Temp_mediatypes;

Picker.delegate = self;

picker.allowsimageediting = YES;

}

[Self presentmodalviewcontroller:picker animated:yes];

[Picker release];

}



2. Photo Callback

-(void) Imagepickercontroller: (Uiimagepickercontroller *) Picker Didfinishpickingmediawithinfo: (NSDictionary *) info

{

NSString *mediatype = [Infoobjectforkey:uiimagepickercontrollermediatype];

BOOL success;

Nsfilemanager *filemanager = [Nsfilemanager Defaultmanager];

Nserror *error;

Nsarray *paths =nssearchpathfordirectoriesindomains (Nsdocumentdirectory,nsuserdomainmask, YES);

NSString *documentsdirectory = [Paths objectatindex:0];

if ([mediatype isequaltostring:@ "Public.image"]) {

UIImage *image = [infoobjectforkey:@ "Uiimagepickercontrollereditedimage"];

NSLog (@ "found an image");

NSString *imagefile = [documentsdirectorystringbyappendingpathcomponent:@ "temp.jpg"];

NSLog (@ "%@", ImageFile);

Success = [FileManager fileexistsatpath:imagefile];

if (success) {

Success = [FileManager removeitematpath:imagefile error:&error];

}

Imageview.image = image;

[UIImageJPEGRepresentation (Image, 1.0f) WriteToFile:imageFileatomically:YES];

SetImage (image);

Cfshow ([[Nsfilemanager Defaultmanager] directorycontentsatpath:[nshomedirectory () stringbyappendingstring:@ "/ Documents "]);

}

else if ([mediatype isequaltostring:@ "Public.movie"]) {

Nsurl *videourl = [Infoobjectforkey:uiimagepickercontrollermediaurl];

NSLog (@ "%@", Videourl);

NSLog (@ "found a video");

NSData *videodata = [NSData Datawithcontentsofurl:videourl];

/****************************************/

NSString *videofile = [documentsdirectorystringbyappendingpathcomponent:@ "Temp.mov"];

NSLog (@ "%@", videofile);

Success = [FileManager fileexistsatpath:videofile];

if (success) {

Success = [FileManager removeitematpath:videofile error:&error];

}

[Videodata Writetofile:videofile Atomically:yes];

Cfshow ([[Nsfilemanager Defaultmanager] directorycontentsatpath:[nshomedirectory () stringbyappendingstring:@ "/ Documents "]);

NSLog (Videourl);

}

[Picker Dismissmodalviewcontrolleranimated:yes];

}


-(void) Imagepickercontrollerdidcancel: (Uiimagepickercontroller *) Picker {

[Picker Dismissmodalviewcontrolleranimated:yes];

}


IOS Camera Features

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.