为什么使用UItouch绘制PNG图像时响应速度慢?

iOS初学者

我使用以下代码通过手指移动来描画PNG。有2个UIImage视图。一个位于背景以将背景图像放置在那里。另一个是清晰的UIImage视图,以在其顶部描边PNG图像。

  -(void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event
   {
       for (UITouch * touch in touches) {

          currentPoint = [touch locationInView:self.view];
          lastPoint = [touch previousLocationInView:self.view];

    //set up array to make space between PNG images
          if (ABS(currentPoint.x-lastPoint.x)>16
               || ABS(currentPoint.y - lastPoint.y) > 13) {

              [brushLocations addObject:[NSValue valueWithCGPoint:currentPoint]];


      }
        [self drawingWithArray];

 }

  - (void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event {

         [brushLocations removeAllObjects];//reset


     }


 -(void)drawingWithArray{



     UIGraphicsBeginImageContext(self.view.frame.size);
     [drawImage.image drawInRect:CGRectMake(0, 0, drawImage.frame.size.width,    drawImage.frame.size.height)];

     for (int i=0; i<[brushLocations count]; i++) {

 CGPoint center =[[brushLocations objectAtIndex:i]CGPointValue];


    // bokehImage is UIImage 

         bokehImage=[bokehImgArray objectAtIndex: i%[bokehImgArray count]];

 /// the PNG images are not semi-transparent, even set the alpha is 0.5??

         [bokehImage drawAtPoint:center blendMode:kCGBlendModeOverlay alpha:0.5f];

//drawImage is uiimage view on top of background image view for stroke PNG images.
     drawImage.image = UIGraphicsGetImageFromCurrentImageContext();
     UIGraphicsEndImageContext();

}

现在,我遇到的问题是响应速度很慢。当手指在设备(IPad4)上移动时,PNG图像不会立即显示。

而且,PNG图像不是半透明的。我想“ drawAtPoint .. blendMode .. alpha”的功能可以使图像半透明(设置为0.5 alpha)。

马特·马特尔

是的,这样的事情应该起作用:

-(void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event
{
    for (UITouch * touch in touches) {
        currentPoint = [touch locationInView:self.view];
        lastPoint = [touch previousLocationInView:self.view];
        //set up array to make space between PNG images
        if (ABS(currentPoint.x-lastPoint.x)>16
            || ABS(currentPoint.y - lastPoint.y) > 13) {
            [brushLocations addObject:[NSValue valueWithCGPoint:currentPoint]];
        }
//        [self drawingWithArray]; // don't call draw routine during touch handler
         [self setNeedsDisplay]; // queue the redraw instead
    }
}

- (void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event
{
// Not needed here
//    [brushLocations removeAllObjects];//reset
}

//-(void)drawingWithArray
- (void)drawRect:(CGRect)rect
{
    // CGContext is already set when drawRect is called
//    UIGraphicsBeginImageContext(self.view.frame.size);
//    [drawImage.image drawInRect:CGRectMake(0, 0, drawImage.frame.size.width, drawImage.frame.size.height)];
    [drawImage.image drawInRect:rect];
    for (int i=0; i<[brushLocations count]; i++) {
        CGPoint center =[[brushLocations objectAtIndex:i]CGPointValue];
        // bokehImage is UIImage
        bokehImage=[bokehImgArray objectAtIndex: i%[bokehImgArray count]];
        // the PNG images are not semi-transparent, even set the alpha is 0.5??
        [bokehImage drawAtPoint:center blendMode:kCGBlendModeOverlay alpha:0.5f];
        //drawImage is uiimage view on top of background image view for stroke PNG images.
        drawImage.image = UIGraphicsGetImageFromCurrentImageContext();
//        UIGraphicsEndImageContext();
    }
    [brushLocations removeAllObjects];//reset
}

本文收集自互联网,转载请注明来源。

如有侵权,请联系[email protected] 删除。

编辑于
0

我来说两句

0条评论
登录后参与评论

相关文章

来自分类Dev

Excel用户窗体按钮单击快速单击时响应速度慢

来自分类Dev

初始服务器响应速度慢

来自分类Dev

响应速度慢和系统滞后

来自分类Dev

为什么istream / ostream速度慢

来自分类Dev

为什么textchangelistener速度慢?

来自分类Dev

为什么Python枚举速度慢?

来自分类Dev

为什么我的查询速度慢?

来自分类Dev

为什么启动速度慢?

来自分类Dev

为什么Matlab Coder速度慢?

来自分类Dev

为什么我的Ubuntu速度慢

来自分类Dev

为什么我的电脑速度慢?

来自分类Dev

为什么在程序上绘制圆比从纹理读取速度慢?

来自分类Dev

为什么在使用UWP时,TapGesture Grid识别器响应速度较慢,但在Android和iOS上运行良好?

来自分类Dev

图像检索速度慢

来自分类Dev

图像检索速度慢

来自分类Dev

为什么get()在多处理中速度慢?

来自分类Dev

为什么get()在多处理中速度慢?

来自分类Dev

为什么大数组Java速度慢

来自分类Dev

反应为什么卸载组件速度慢

来自分类Dev

为什么我的LDAP登录速度慢?

来自分类Dev

为什么我的无线速度慢?

来自分类Dev

在CodeFluent中使用列表时收集速度慢

来自分类Dev

在 Oracle 中使用 datediff 函数时查询速度慢

来自分类Dev

nginx和php5-fpm使用Laravel应用程序的响应速度非常慢

来自分类Dev

Python | 为什么访问实例属性的速度比本地速度慢?

来自分类Dev

为什么ServiceStack返回POCO对象的速度比.NET Remoting返回数据集的速度慢?

来自分类Dev

为什么在LinkedLists中在特定索引处添加的速度比ArrayLists中的速度慢

来自分类Dev

为什么数组元素的平均打印速度比C ++中单个对象的打印速度慢?

来自分类Dev

为什么我的Python脚本运行速度比HeapSort实现上的速度慢?

Related 相关文章

热门标签

归档