在自定义视图中为位图创建阴影(create shadow for bitmap in custom view)

编程入门 行业动态 更新时间:2024-10-24 22:24:57
在自定义视图中为位图创建阴影(create shadow for bitmap in custom view)

我有一个包含一些位图的自定义视图,我想为它们设置阴影,为此,我使用此代码:

shadowPaints=new Paint(Paint.ANTI_ALIAS_FLAG); shadowPaints.setShadowLayer(10.0f, 3.0f, 2.0f, Color.BLACK); canvas.drawBitmap(bmp, matrix, shadowPaints); setLayerType(LAYER_TYPE_SOFTWARE, shadowPaints);

我的结果是 你可以看到我的影子实际上是另一个具有不同x和y位置的位图,但我想要的是我的影子是纯色位图。 任何人都可以帮我这个吗?

I have a custom view wich contain some bitmaps and I want to set shadows for them, for that, I use this code:

shadowPaints=new Paint(Paint.ANTI_ALIAS_FLAG); shadowPaints.setShadowLayer(10.0f, 3.0f, 2.0f, Color.BLACK); canvas.drawBitmap(bmp, matrix, shadowPaints); setLayerType(LAYER_TYPE_SOFTWARE, shadowPaints);

and my result is as you can see my shadow actually is another bitmap with different x and y position but what I want is my shadow be a solid color bitmap. can anyone help me about this?

最满意答案

setShadowLayer实际上是用于在文本上添加阴影。

如果您已经知道要绘制的位图,则可以在PhotoShop中添加阴影并一次绘制位图和阴影。

如果您不想这样做,可以通过制作图像副本来制作阴影, 使用PorterDuff过滤器将其全部变为灰色 , 使用Renderscript模糊图像 ,并在画布上以x绘制,在绘制实际图像之前的y偏移量。

就个人而言,我认为PhotoShop要容易得多。

setShadowLayer is actually meant for putting shadows on text.

If you already know the bitmap you want to draw, you can just add a shadow in PhotoShop and draw the bitmap and shadow all at once.

If you don't want to do that, you could make a shadow by making a copy of the image, using a PorterDuff filter to make it all grey, use Renderscript to blur the image, and draw it on the canvas at an x,y offset before drawing the actual image on top of it.

Personally, I think PhotoShop is a lot easier.

更多推荐

本文发布于:2023-07-22 18:30:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1222340.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:位图   自定义   视图   中为   阴影

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!