我有一个简单的应用程序,我可以在其中拍照或选择相机胶卷上的现有照片,然后在 UIImageView 中显示图像。我想要一个按钮,您可以按下并反转拾取的图像,然后将其显示在相机胶卷中。我的问题是,如何反转 UIImage 的颜色,然后使用新的反转颜色在 ImageView 中显示?我看过与此相关的其他帖子,但没有人解释如何实现代码。我对 xcode 相当陌生,希望得到所有反馈。
这是视图控制器的 .m 文件:
#import "ViewController.h"
@interface ViewController ()
@end
@implementation ViewController
@synthesize imageView;
- (void)viewDidLoad
{
[super viewDidLoad];
// Do any additional setup after loading the view, typically from a nib.
}
- (void)didReceiveMemoryWarning
{
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
-(IBAction)takePhoto {
picker1 = [[UIImagePickerController alloc] init];
picker1.delegate = self;
[picker1 setSourceType:UIImagePickerControllerSourceTypeCamera];
[self presentViewController:picker1 animated:YES completion:nil];
}
-(IBAction)ChooseExisting {
picker2 = [[UIImagePickerController alloc] init];
picker2.delegate = self;
[picker2 setSourceType:UIImagePickerControllerSourceTypePhotoLibrary];
[self presentViewController:picker2 animated:YES completion:nil];
}
-(IBAction)invertImage {
}
-(void) imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info {
imageFinal = [info objectForKey:UIImagePickerControllerOriginalImage];
[imageView setImage:imageFinal];
[self dismissViewControllerAnimated:YES completion:nil];
}
-(void)imagePickerControllerDidCancel:(UIImagePickerController *)picker {
[self dismissViewControllerAnimated:YES completion:nil];
}
@end