如何从蒙版图像中移动和裁剪图像? [英] How to move and crop image from masked image?

查看:166
本文介绍了如何从蒙版图像中移动和裁剪图像?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我借助以下链接成功屏蔽了图片:

I have masked image successfully with the help of following link:

如何掩盖UIImageView

在上面的链接中有两个名为 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;
        }];
    }
}

这篇关于如何从蒙版图像中移动和裁剪图像?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆