【问题标题】:iOS - Objective-C: Image manipulation and processingiOS - Objective-C:图像操作和处理
【发布时间】:2016-11-03 12:12:19
【问题描述】:

我正在开发一个 iOS 应用程序(目标 C),我需要在其中处理 图像操作。

应用模块中要做的功能是,

获取您要编辑的任何图像(父图像)。然后将其他图像(如明喻、表情符号、贴纸)放入该图像中。子图像应在父图像范围内可缩放、可旋转、可拖动。

我成功管理了子图像的缩放、旋转、拖动效果。

但问题是,在缩放、旋转、拖动子图像的过程中,位于父图像之外的图像部分会变得模糊或低于父图像内部的图像部分的 alpha 值.

我附上了我正在寻找的输出的参考屏幕截图。

This is the reference image of the output, I am looking for

编辑:这里是代码 sn-p。

UIImageView* randomView = [[UIImageView alloc] initWithFrame:CGRectMake(130, 200, 100, 100)];
        randomView.image = image; //image coming from gallery
        randomView.userInteractionEnabled = YES;
        randomView.alpha = 0.8;

        imageView.backgroundColor = [UIColor clearColor];
        imageView.opaque = NO;

        randomView.backgroundColor = [UIColor clearColor];
        randomView.opaque = NO;

        [self addPanGesture:randomView];
        [self addPinchGesture:randomView];
        [self addRotateGesture:randomView];

        [imageView addSubview:randomView];

【问题讨论】:

  • 提供您的代码和有关实施的更多详细信息,以便更好地理解问题。
  • 试试这个:self.imageView.clipToBounds = YES
  • 请查看代码视图的编辑。 @同志

标签: ios objective-c image uiimageview uiimage


【解决方案1】:

我认为您要求的这个演示...... 检查这个演示:

http://sugartin.info/2011/10/21/mask-and-crop-of-an-image/

首先用另一种图像形状裁剪图像,然后在演示中替换以下函数以获得您的要求......

- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info {
    [picker dismissModalViewControllerAnimated:YES];
    UIImage *img =  [info objectForKey:@"UIImagePickerControllerOriginalImage"];

    self.image_view.image=[self maskImage:img withMask:[UIImage imageNamed:@"frame.png"]];
    UIImageView *viewImg=[[UIImageView alloc]initWithFrame:self.image_view.frame];
    viewImg.image=img;
    viewImg.alpha=0.4;
    [self.view addSubview:viewImg];
    [self.view sendSubviewToBack:viewImg];

}

这个演示给了我这种类型的结果...

如果您只想用另一个图像屏蔽图像功能, Here 是..

- (UIImage*) maskImage:(UIImage *)image withMask:(UIImage *)maskImage {

    CGImageRef maskRef = maskImage.CGImage; 

    CGImageRef mask = CGImageMaskCreate(CGImageGetWidth(maskRef),
        CGImageGetHeight(maskRef),
        CGImageGetBitsPerComponent(maskRef),
        CGImageGetBitsPerPixel(maskRef),
        CGImageGetBytesPerRow(maskRef),
        CGImageGetDataProvider(maskRef), NULL, false);

    CGImageRef masked = CGImageCreateWithMask([image CGImage], mask);
    return [UIImage imageWithCGImage:masked];

}

希望这会有所帮助..让我知道这是否有效...谢谢.. :)

【讨论】:

    猜你喜欢
    • 2017-04-16
    • 2011-05-16
    • 1970-01-01
    • 2017-06-13
    • 2019-07-17
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-03-06
    相关资源
    最近更新 更多