绘制位图作为 SurfaceView 背景
我目前正在使用 Canvas.drawBitmap()
将 Bitmap
绘制到 SurfaceView
。这似乎确实降低了我的帧速率,我想知道我能做些什么来解决这个问题。我引用了在 onDraw()
方法之外创建的位图。我已确保图像小、不透明、像素格式匹配...等。当我不绘制图像时,帧速率会上升约 10-15 FPS。有什么想法可以加快速度吗?我经历了明显的滞后。
我在所有内容之外创建位图...
private Bitmap bitmapPlayer = BitmapFactory.decodeResource(getResources(), R.drawable.player);
然后在我的 onDraw() 方法中...
canvas.drawBitmap(bitmapPlayer, null, drawingRect, null); // drawingRect is the Rect to draw the Bitmap inside of
// ... Rest of drawing code
I am currently drawing a Bitmap
to a SurfaceView
using Canvas.drawBitmap()
. This seems to really reduce my framerate and I was wondering what I can do to fix this. I reference a bitmap that I have created outside the onDraw()
method. I have made sure that the image is small, opaque, the pixel formats match... etc. When I don't draw the image the framerate goes up by about 10-15 FPS. Any ideas to speed this up? I experience a noticeable lag.
I create the bitmap outside of everything...
private Bitmap bitmapPlayer = BitmapFactory.decodeResource(getResources(), R.drawable.player);
Then in my onDraw() method...
canvas.drawBitmap(bitmapPlayer, null, drawingRect, null); // drawingRect is the Rect to draw the Bitmap inside of
// ... Rest of drawing code
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我只能假设您在绘图调用中做了一些逻辑繁重的事情,如果您没有看到代码与以下示例之间有任何差异,
http://www.droidnova.com/playing-with-graphics-in-android-part-iii,176.html
我会开始研究以下,并利用图形硬件进行绘图。
http://developer.android.com/resources/articles/glsurfaceview.html
希望这有帮助
I can only assume you are doing something logic heavy in your draw call, If you don't see any differences between your code and the following example,
http://www.droidnova.com/playing-with-graphics-in-android-part-iii,176.html
I would start to take a look into the following, and utilizing the graphics hardware for your drawing.
http://developer.android.com/resources/articles/glsurfaceview.html
Hope this helps
您用于背景的位图有多大。如果它太大并且只有一种尺寸并且不是为 hdpi、mdpi 等创建的,那么您可能引用了不必要的大图像。如果是这种情况,我将使用 BitmapFactory 类创建与画布的宽度和高度相匹配的图像的缩小版本。
建议使用 PS png 图像,因为它们是最有效的。
How large is the Bitmap you are using for the background. If it is over-sized and only one size and not created for hdpi, mdpi, etc, then you may be referencing a image unnecessarily large. If this is the case, I would use the BitmapFactory class to create a scaled down version of the image that matches the width and height of the Canvas.
P.S. png images are recommended as they are most efficient.