【发布时间】:2015-06-21 00:52:26
【问题描述】:
我计划创建一个图像编辑应用程序。第一步,我将触摸的图像位置显示到与原始图像视图不同的图像视图中。
使用 默认图片(从 xcode storyboard 属性检查器设置)测试时效果很好。
但当我从设备“照片”导入照片时,它不会裁剪精确的图像。
我真的很困惑并坚持在那里。请有人指导我完成这项任务。
我尝试了下面的代码
提前致谢。
- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info
{
UIImage *image = [info valueForKey:UIImagePickerControllerEditedImage];
imgVw.image = image;
// croperImgvw.image = [self cropImage : image];
[self dismissViewControllerAnimated:YES completion:NULL];
}
- (void)imagePickerControllerDidCancel:(UIImagePickerController *)picker
{
[self dismissViewControllerAnimated:YES completion:NULL];
}
- (UIImage *)cropImage:(UIImage *)image : (CGPoint)point
{
CGRect clippedRect =CGRectMake(point.x, point.y, 50, 50);
CGImageRef imageRef = CGImageCreateWithImageInRect([image CGImage], clippedRect);
UIImage * croppedImage = [UIImage imageWithCGImage:imageRef];
CGImageRelease(imageRef);
return croppedImage;
}
-(void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event
{
UITouch *touch = [touches anyObject];
CGPoint touch_point = [touch locationInView:self.view];
NSLog(@"X location: %f", touch_point.x);
NSLog(@"Y Location: %f",touch_point.y);
CGPoint point = [touch locationInView:self.view];
croperImgvw.image = [self cropImage:[imgVw image] :point];
}
【问题讨论】:
标签: ios objective-c uiimage crop xcode6.1