以下は、ソースから画像を取得してトリミングするために使用するコードです
これが私がソースと宛先を選択する方法です
- (void)actionSheet:(UIActionSheet *)actionSheet clickedButtonAtIndex:(NSInteger)buttonIndex
{
//Get the name of the current pressed button
NSString *buttonTitle = [actionSheet buttonTitleAtIndex:buttonIndex];
if ([buttonTitle isEqualToString:@"Camera Library"]) {
[self performSelector:@selector(pickImage:) ];
}
if ([buttonTitle isEqualToString:@"Camera"]) {
[self performSelector:@selector(startcamera:) ];
}
if ([buttonTitle isEqualToString:@"Cancel"]) {
NSLog(@"Cancel pressed --> Cancel ActionSheet");
}
}
- (IBAction) pickImage:(id)sender
{
if([UIImagePickerController isSourceTypeAvailable:
UIImagePickerControllerSourceTypePhotoLibrary])
{
UIImagePickerController *picker= [[UIImagePickerController alloc]init];
picker.delegate = self;
picker.sourceType = UIImagePickerControllerSourceTypePhotoLibrary;
[self presentModalViewController:picker animated:YES];
[picker release];
}
}
- (void)imagePickerController:(UIImagePickerController *)picker
didFinishPickingMediaWithInfo:(NSDictionary *)info {
self.lastChosenMediaType = [info objectForKey:UIImagePickerControllerMediaType];
if ([lastChosenMediaType isEqual:(NSString *)kUTTypeImage]) {
UIImage *chosenImage = [info objectForKey:UIImagePickerControllerEditedImage];
UIImage *shrunkenImage = shrinkImage(chosenImage, imageFrame.size);
self.imagee = shrunkenImage;
selectImage.image = imagee;
}
[picker dismissModalViewControllerAnimated:YES];
}
-(void)imagePickerControllerDidCancel:(UIImagePickerController *) picker
{
[picker dismissModalViewControllerAnimated:YES];
}
#pragma mark -
static UIImage *shrinkImage(UIImage *original, CGSize size) {
CGFloat scale = [UIScreen mainScreen].scale;
CGColorSpaceRef colorSpace = CGColorSpaceCreateDeviceRGB();
CGContextRef context = CGBitmapContextCreate(NULL, size.width * scale,
size.height * scale, 8, 0, colorSpace, kCGImageAlphaPremultipliedFirst);
CGContextDrawImage(context,
CGRectMake(0, 0, size.width * scale, size.height * scale),
original.CGImage);
CGImageRef shrunken = CGBitmapContextCreateImage(context);
UIImage *final = [UIImage imageWithCGImage:shrunken];
CGContextRelease(context);
CGImageRelease(shrunken);
return final;
}
- (void)updateDisplay {
if ([lastChosenMediaType isEqual:(NSString *)kUTTypeImage]) {
imageView.image = imagee;
imageView.hidden = NO;
}
}
- (IBAction) startcamera:(id)sender
{
if([UIImagePickerController isSourceTypeAvailable:UIImagePickerControllerSourceTypeCamera])
{
UIImagePickerController *picker = [[[UIImagePickerController alloc]init]autorelease];
picker.delegate = self;
picker.sourceType = UIImagePickerControllerSourceTypeCamera;
picker.allowsEditing=NO;
[self presentModalViewController: picker animated:YES];
}else {
UIAlertView *alt = [[UIAlertView alloc]
initWithTitle:@"Error"
message:@"Camera Image Source Not Available"
delegate:nil cancelButtonTitle:@"OK"
otherButtonTitles:nil];
[alt show];
[alt release];
}
}
updateDisplay このメソッドは viewDidAppear で呼び出されます。
今私の問題は、画像ピッカービューが開くことです。ライブラリ画像が表示されますが、選択すると閉じられ、トリミング画像画面に移動しませんはい、mobileCoreServiceフレームワークを使用しました