简体   繁体   English

将位图绘制为SurfaceView背景

[英]Drawing a Bitmap as a SurfaceView Background

I am currently drawing a Bitmap to a SurfaceView using Canvas.drawBitmap() . 我目前正在使用Canvas.drawBitmap()Bitmap绘制到SurfaceView 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. 我引用了在onDraw()方法之外创建的位图。 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. 我确保图像很小,不透明,像素格式匹配...等等。当我不绘制图像时,帧速率会提高约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... 然后在我的onDraw()方法中...

canvas.drawBitmap(bitmapPlayer, null, drawingRect, null); // drawingRect is the Rect to draw the Bitmap inside of
// ... Rest of drawing code

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 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 http://developer.android.com/resources/articles/glsurfaceview.html

Hope this helps 希望这可以帮助

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. 如果尺寸过大,并且仅为一种尺寸而未为hdpi,mdpi等创建尺寸,则可能是所引用的图像不必要地大。 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. 如果是这种情况,我将使用BitmapFactory类创建与Canvas的宽度和高度匹配的按比例缩小的图像版本。

PS png images are recommended as they are most efficient. 建议使用PS png图像,因为它们效率最高。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM