IPAD调用摄像头 相册

 

ipad打开相册和调用摄像头的方法跟iPhone 不一样  用 UIPopoverController 显示

 

- (void) actionSheet:(UIActionSheet *)actionSheet clickedButtonAtIndex:(NSInteger)buttonIndex{

    AppDelegate *app = (AppDelegate *)[UIApplication sharedApplication].delegate;

    if(buttonIndex==0){

        //        拍照

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

        picker.delegate = self;

        picker.allowsEditing = NO;//是否允许编辑

        picker.sourceType = UIImagePickerControllerSourceTypeCamera;

    

        UIPopoverController *popover=[[UIPopoverController alloc] initWithContentViewController:picker];

   

        self.popoverController = popover;

        

        [popover presentPopoverFromRect:CGRectMake(0, 0, 800, 800) inView:app.window permittedArrowDirections:UIPopoverArrowDirectionAny animated:YES];

        [picker release];  

        [popover release];

    }else if(buttonIndex==1){

         

        //        相册里找

        UIImagePickerController *imagePickerController = [[UIImagePickerController alloc] init];

        imagePickerController.delegate = self;

        imagePickerController.sourceType = UIImagePickerControllerSourceTypePhotoLibrary;

        

        UIPopoverController *popover=[[UIPopoverController alloc] initWithContentViewController:imagePickerController];

        self.popoverController = popover;

       

        [popover presentPopoverFromRect:CGRectMake(0, 0, 800, 800) inView:app.window permittedArrowDirections:UIPopoverArrowDirectionRight animated:YES];

        [imagePickerController release];

        [popover release];

        

    }

    [actionSheet release];

 

}

 

 

-(void) imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *) info{

  

    UIImage *img=[info objectForKey:@"UIImagePickerControllerOriginalImage"];

    UIImage *newImg=[self scaleImage:img toScale:1];

    [self saveImage:newImg WithName:[NSString stringWithFormat:@"%@%@",[self generateUuidString],@".png"]];

    [imageMuArray addObject:newImg];

 

}

 

- (void)saveImage:(UIImage *)tempImage WithName:(NSString *)imageName

 

{

    

    NSData* imageData = UIImagePNGRepresentation(tempImage);

    

    NSArray* paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory,NSUserDomainMask,YES);

    

    NSString* documentsDirectory = [paths objectAtIndex:0];

    

    // Now we get the full path to the file

    

    NSString* fullPathToFile = [documentsDirectory stringByAppendingPathComponent:imageName];

    // and then we write it out

    NSLog(@"--fullPathToFile:%@",fullPathToFile);

  [[MySingletonClassesshareMySingleton].replyImagePathMuArrayaddObject:fullPathToFile];

    [imageData writeToFile:fullPathToFile atomically:NO];

    

}

 

- (NSString *)generateUuidString

{

    // create a new UUID which you own

    CFUUIDRef uuid = CFUUIDCreate(kCFAllocatorDefault);

    

    // create a new CFStringRef (toll-free bridged to NSString)

    // that you own

    NSString *uuidString = (NSString *)CFUUIDCreateString(kCFAllocatorDefault, uuid);

    

    // transfer ownership of the string

    // to the autorelease pool

    [uuidString autorelease];

    

    // release the UUID

    CFRelease(uuid);

    

    return uuidString;

 

}

 

-(UIImage *)scaleImage:(UIImage *)image toScale:(float)scaleSize

{

    UIGraphicsBeginImageContext(CGSizeMake(image.size.width*scaleSize,image.size.height*scaleSize));

    [image drawInRect:CGRectMake(0, 0, image.size.width * scaleSize, image.size.height *scaleSize)];

    UIImage *scaledImage = UIGraphicsGetImageFromCurrentImageContext();

    UIGraphicsEndImageContext();

    return scaledImage;

 

}

你可能感兴趣的:(ipad)