【问题标题】:UIImage remove some pixels issueUIImage 删除一些像素问题
【发布时间】:2013-05-17 10:11:21
【问题描述】:

我有用户可以擦除图像的应用程序。

因此,如果用户触摸图像的某些像素,这些像素的 alfa 应该会变低。

例如,如果我触摸图像的 (0,0) 像素一次,则 (0,0) 像素的不透明度应该变为 0.9。如果我触摸该像素 10 次,我不应该在点 (0,0) 看到图像。

实现它的最佳方法是什么?

【问题讨论】:

  • 如果你能精确触摸 (0,0) 像素,你的手指一定很小
  • 可以使用Quartz核心框架。参考raywenderlich.com/18840/…
  • 一个像素只是举例

标签: iphone uiimage quartz-2d cgcontext cgcontextref


【解决方案1】:

这是您可以检测触摸值的 coe

CGPoint StartPoint = [touch previousLocationInView:self];

CGPoint Endpoint = [touch locationInView:self];


NSString *str = [NSString stringWithFormat:@"%f",StartPoint.x];
NSString *strlx = [NSString stringWithFormat:@"%f",StartPoint.y];
NSString *strcx = [NSString stringWithFormat:@"%f",Endpoint.x];
NSString *strcy = [NSString stringWithFormat:@"%f",Endpoint.y];

这里的 touch 是 UITouch 的对象。

关于不透明度我不能说什么。

【讨论】:

  • 我不需要获取触摸坐标,我需要更改适当的像素
【解决方案2】:

如果您想要快速(如实时快速),则需要使用 OpenGL。 最好的方法是创建一个 alpha 值蒙版,该蒙版将使用自定义构建的着色器应用于原始图像。

更简单但速度较慢的方法是从 UIImage 获取原始像素 并在原始像素数组上应用 alpha 值,然后将其转回 UIImage (here is a nice example)

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2013-08-25
    • 1970-01-01
    • 2017-06-20
    • 2010-10-17
    • 1970-01-01
    • 1970-01-01
    • 2017-04-01
    • 2018-08-15
    相关资源
    最近更新 更多