【问题标题】:Android - Apply a bitmap texture to API drawing routinesAndroid - 将位图纹理应用于 API 绘图例程
【发布时间】:2013-02-27 14:28:34
【问题描述】:

我有一个跨越整个屏幕的位图,它将用作我需要绘制到画布上的 Path 对象的纹理。然后我有一个背景图像,需要在上面绘制这个纹理路径。

我尝试使用 PorterDuff 模式,但似乎无法正常工作。我很难弄清楚 PorterDuff 模式是如何运作的,因为它们似乎都不像 I always thought they were supposed to function 那样运作。

我已经找到了一种使用此测试代码来纹理路径的方法:

Paint paint = new Paint();
    //draw the texture
canvas.drawBitmap(BitmapFactory.decodeResource(getResources(), R.drawable.texture),0,0,paint);
   //construct the Path with an inverse even-odd fill
Path p = new Path();
p.setFillType(Path.FillType.INVERSE_EVEN_ODD);
p.addCircle(this.getHeight()/2, this.getWidth()/2, 200, Path.Direction.CCW);
   //use CLEAR to remove inverted fill, thus showing only the originally filled section
paint.setXfermode(new PorterDuffXfermode(android.graphics.PorterDuff.Mode.CLEAR));
   //draw path
canvas.drawPath(p, paint);

但我不知道如何将其放置在背景图像之上。我只是使用了 PorterDuff 模式错误吗?

【问题讨论】:

    标签: android textures android-canvas porter-duff


    【解决方案1】:

    也许我的问题可以引导您找到解决方案:

    在您的drawPath 通话中使用的paint
    油漆风格是什么?
    笔画宽度是多少?
    什么是笔触/填充颜色?

    如果您不使用描边/填充颜色,而是使用纹理,那么对绘画的setShader 的调用在哪里(使用BitmapShader)?

    【讨论】:

    • 样式是填充,这是唯一重要的部分,因为您不应该看到填充颜色或笔触。我会使用 BitmapShader,但我不知道有什么方法可以修改纹理的坐标以按照我想要的方式对齐它。有没有我不知道的方法?
    猜你喜欢
    • 2013-02-02
    • 2019-07-03
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-06-18
    • 2019-02-02
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多