在表面视图上绘制透明图像
我的目标是在图像上运行发光动画。我正在更改图像 Alpha 以产生这种效果。
我已经使用了android框架中提供的基本AlphaAnimation,但发现它减慢了其他动画的速度。所以我从 SurfaceView 扩展了一个类并创建了一个线程来更新它。 (再次在这里,我正在操纵图像的阿尔法)。
一切看起来都很好,除了我无法在 SurfaceView 上绘制透明图像。它在位图的透明区域上显示黑色。
Canvas mCanvas = holder.lockCanvas(null);
Bitmap mybit = BitmapFactory.decodeResource(mFrameLayout.getResources(), R.drawable.icon);
mCanvas.drawColor(0, Mode.CLEAR);
mCanvas.drawBitmap(mybit, 0, 0, null);
holder.unlockCanvasAndPost(mCanvas);
提前致谢。
My objective is to run a glowing animation on an image.I am changing the image alpha to produce this effect.
I have used basic AlphaAnimation provided in android framework but found that its slowing down other animations. So i extended a class from SurfaceView and created a thread to update it. ( Again here, i am manipulating alpha of the image ).
Everything seems fine, except that i am not able to draw a transparent image onto SurfaceView.Its showing black color on the transparent areas of the bitmap.
Canvas mCanvas = holder.lockCanvas(null);
Bitmap mybit = BitmapFactory.decodeResource(mFrameLayout.getResources(), R.drawable.icon);
mCanvas.drawColor(0, Mode.CLEAR);
mCanvas.drawBitmap(mybit, 0, 0, null);
holder.unlockCanvasAndPost(mCanvas);
Thanks in advance.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
示例中有一个旋转立方体的示例。你应该看看它是如何获得透明背景的。
There is an example of a Spinning cube in the samples. You should be have to have a look at that and see how they got a transparent background.
我没有尝试过,但我假设您将 Paint 的颜色设置为透明颜色,然后使用 Paint 对象来绘制位图。
I haven't tried, but I assume you set the color of the Paint to a transparent one, and then use the Paint object to draw your bitmap.