【问题标题】:how to draw on the surface of imageview transparently如何透明地在imageview的表面上绘制
【发布时间】:2009-12-17 05:14:54
【问题描述】:

我想跟踪手指触摸并在 imageView 顶部绘制路径。 以下是我所做的:

在触摸事件中:

UIgraphicsBeginImageContext(imageView.frame.size);
[imageView.image drawInRect:CGRectMake(0,0,imageView.size.width,imageView.size.height)];

//drawing.....
imageView.image=UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();

但是,绘制的背景图像不透明? 如何在绘制路径的同时还能使背景可用?

提前致谢:)

【问题讨论】:

    标签: iphone cocoa-touch core-graphics


    【解决方案1】:

    如果您正在绘制简单的矢量图,您可以设置具有非 1.0 alpha 值的颜色。当您在图像上绘制它们时,这些形状将是半透明的。例如:

    CGColorSpaceRef space = CGColorSpaceCreateDeviceRGB();
    CGFloat values[4] = {1.0, 0.0, 0.0, 0.5}; 
    CGColorRef translucentRed = CGColorCreate(space, values); 
    
    CGContextSetStrokeColorWithColor(context, translucentRed);
    CGContextSetFillColorWithColor(context, translucentRed)
    
    // Do your drawing here
    
    CGColorRelease(translucentRed);
    CGColorSpaceRelease(space);
    

    将创建一个半透明的红色并设置当前的描边和填充使用该颜色。

    请注意,由于这种半透明,重叠的绘制元素将具有较暗的区域,这可能是您不想要的效果。

    【讨论】:

      猜你喜欢
      • 2012-04-19
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2019-09-10
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多