如何从蒙版图像中移动和裁剪图像?
我借助以下链接成功屏蔽了图片:
I have masked image successfully with the help of following link:
在上面的链接中有两个名为 image.png 的图像和 mask.png ,
In above link there are two images named image.png and mask.png ,
屏蔽图像后,我想裁剪结果图像。
After masking the image i want to crop the result image.
我担心的是我要裁剪名为 image.png 的图像,但 mask.png 应该保持不变,因为它是。我正在使用 KICropImageView
https://github.com/zhangzhixun / CropImageDemo 用于裁剪图像。
My concern is that I want to crop the image named image.png but mask.png should be stay still as it is. I am using KICropImageView
https://github.com/zhangzhixun/CropImageDemo for cropping the Image.
但是当我滚动图像时,我的整个结果图像正在滚动,但我只想滚动 image.png 而不是 mask.png 图片。
But when I scroll the image my whole result image is scrolling but I just want to scroll image.png not mask.png image.
任何想法我该怎么做?
你可以使用PanGesture ..
You Can Use PanGesture..
- (void)viewDidLoad
{
[super viewDidLoad];
UIPanGestureRecognizer *pan1 = [[UIPanGestureRecognizer alloc] initWithTarget:self action:@selector(handlePanImage:)];
self.imageview.userInteractionEnabled = YES;
[self.imageview addGestureRecognizer:pan1];
}
**after called Method handlePanImage..**
- (void)handlePanImage:(UIPanGestureRecognizer *)sender
{
static CGPoint originalCenter;
if (sender.state == UIGestureRecognizerStateBegan)
{
originalCenter = sender.view.center;
sender.view.alpha = 0.8;
[sender.view.superview bringSubviewToFront:sender.view];
}
else if (sender.state == UIGestureRecognizerStateChanged)
{
CGPoint translation = [sender translationInView:self.view];
sender.view.center = CGPointMake(originalCenter.x + translation.x, originalCenter.y + translation.y);
}
else if (sender.state == UIGestureRecognizerStateEnded || sender.state == UIGestureRecognizerStateCancelled || sender.state == UIGestureRecognizerStateFailed)
{
// do whatever post dragging you want, e.g.
// snap the piece into place
[UIView animateWithDuration:0.2 animations:^{
CGPoint center = sender.view.center;
center.x = round(center.x / 50.0) * 50.0;
center.y = round(center.y / 50.0) * 50.0;
sender.view.center = center;
sender.view.alpha = 1.0;
}];
}
}