iOS中的自定义图像蒙版 [英] Custom image mask in iOS

查看:184
本文介绍了iOS中的自定义图像蒙版的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我遇到了屏蔽图片的问题。我做游戏拼图,并且必须制作自定义图像。我发现并尝试了两种自定义裁剪方式:

I have a issue with masking images. I do game "puzzle" and have to make custom images. I found and tried 2 way of custom cropping:


  1. 使用 CALayer.mask 属性。

  2. 使用 UIImage.mask 属性。

  1. Using CALayer.mask property.
  2. Using UIImage.mask property.

在第一个选项中,我创建自定义路径,然后将其分配给 CAShapeLayer.path property,然后将 CAShapeLayer 分配给 CALayer.mask 属性。最后我有自定义裁剪图像。
在第二个选项中我首先使用 CGImageMaskCreate()方法(我使用以前创建的拼图的黑色蒙版图像),然后 CGContextClipToMask()
在任何一个选项中我都有性能问题(主要是当我将图像裁剪成16个谜题并在屏幕上拖动时)。

In first option i create my custom path, then assign it to CAShapeLayer.path property, then assign CAShapeLayer to CALayer.mask property. At the end i have custom cropped image. In second option i use firstly use CGImageMaskCreate() method (i use previously created black mask images of puzzle), then CGContextClipToMask(). In either options i have problem with performance (mostly when i crop image into 16 puzzles and drag in over the screen).

有没有其他方法以自定义方式裁剪图像。
(我不知道如何解决性能问题)。
提前致谢。

Is there any other approaches to crop image in custom way. (I don't know how to solve performance problem). Thanks in advance.

推荐答案

你可以使用很多UIImage类别。给我一点时间,我会在这里发布一些链接:

There are lots of UIImage-categories out there you can use for this. Give me a moment and I'll post some links here:

  • Cropping an UIImage (not really a category though, but it'll fit)
  • UIImage: Resize, then Crop
  • https://sites.google.com/a/injoit.com/knowledge-base/for-developers/graphics/uiimage-routines-scaling-cropping-rotating-etc
  • http://www.hive05.com/2008/11/crop-an-image-using-the-iphone-sdk/
  • http://maybelost.com/2010/11/cropping-a-uiimage-on-iphone/

这篇关于iOS中的自定义图像蒙版的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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