UIImage中的图形被扭曲了


不丶离
2025-04-14 06:20:01 (1月前)
  1. 计数]; [R ++)

{
CGRect rect = [[rectangles objectAtIndex:r] CGRectValue];

  1. //获取矩形的边缘
  2. CGFloat


xEdge
</跨度>
= rect.origin.x + rect.size.width;
CGFloat yEdge = rect.origin.y + rect.size.height;

  1. if((currPoint.xgt; rect.origin.xamp;&amp; currPoint.xlt;


xEdge
</跨度>
)&amp;&amp; (currPoint.y&lt; rect.origin.y&amp;&amp; currPoint.y&gt; yEdge))
{
imgView.image = [自我

2 条回复
  1. 0# 早岁那知世事艰 | 2019-08-31 10-32



    我无法确切地告诉你为什么会出现这些文物,但……



    我不认为在触摸处理程序中渲染图像是个好主意。触摸处理应该尽可能少。



    您可能想尝试使用CoreAnimation

    CALayer




    将您的图像设置为这样的背景图像(假设您的类是其子类

    UIView

    )或使用实际的

    UIImageView





    1. self.layer.contents = (id)image.CGImage;

    2. </code>


    当您检测到另一个矩形时

    rect

    已触摸,将突出显示添加为图像背景上方的子图层:




    1. CALayer *highlightLayer = [CALayer layer];
      highlightLayer.frame = rect;
      highlightLayer.backgroundColor = [UIColor yellowColor].CGColor;
      highlightLayer.opacity = 0.25f;
      [self.layer addSublayer:highlightLayer];

    2. </code>




    shouldRasterize

    如有必要,图层属性可能有助于提高性能:




    1. self.layer.shouldRasterize = YES;

    2. </code>


    为了使用所有这些,使用QuartzCore框架并导入



    在您的实现文件中。



    您可以通过渲染来创建图层层次结构的PNG表示

    self.layer

    到图像上下文,然后获取图像和PNG表示。


登录 后才能参与评论