我有一个包含一些位图的自定义视图,我想为它们设置阴影,为此,我使用此代码:
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.
更多推荐
发布评论