我正在尝试在图像视图中从相册加载图像,然后单击一个按钮调整大小,然后单击另一个按钮以新大小保存图像。
除了保存的图像与原始图像大小相同之外,一切都运行良好。
这是我到目前为止所做的:
- (IBAction)chooseImage:(id)sender
{
self.imagePicker = [[UIImagePickerController alloc] init];
self.imagePicker.delegate = self;
[self.imagePicker setSourceType:UIImagePickerControllerSourceTypePhotoLibrary];
[self presentViewController:self.imagePicker animated:YES completion:nil];
}
- (void) imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info
{
self.chosenImage = info[UIImagePickerControllerOriginalImage];
[self.imageView setImage:self.chosenImage];
[self dismissViewControllerAnimated:YES completion:nil];
}
- (void) imagePickerControllerDidCancel:(UIImagePickerController *)picker
{
[self dismissViewControllerAnimated:YES completion:nil];
}
- (void)didReceiveMemoryWarning
{
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
- (IBAction)reSize:(id)sender
{
CGRect newFrame = CGRectMake(20, 49, 280, 200);
[UIView animateWithDuration:0.25f
animations:^{
self.imageView.frame = newFrame;
}];
}
- (IBAction)saveImage:(id)sender
{
UIImageWriteToSavedPhotosAlbum(_chosenImage, self, nil, nil);
}
@end