开发者

Bitmap.getBitmapResource() - Memory question

I was wondering if multiple calls to Bitmap.getBitmapResource() for the same image will l开发者_开发百科ead to multiple Bitmap instances being created? Or, does each return value point to the same memory? The official documentation doesn't seem to be very helpful. I use this call to set the same background images for a bunch of my screens, so should I just create a cache to load it into memory and return the same object for each screen?

Here is the relevant documentation:

public static Bitmap getBitmapResource(String name)

    Creates a bitmap from provided name resource.

    This method looks for the resource in both the .cod file that called this method and any .cod files that it relies on. The resource files are automatically generated by the compiler when a new graphic (PNG, GIF, or, JPG) is added to a project.

    Parameters:
        name - Name of the bitmap resource.
    Returns:
        New Bitmap object, or null if this method couldn't find your named resource.
    Throws:
        NullPointerException - If the name parameter is null.
    Since:
        JDE 4.0.2


You will get a new Bitmap instance for each call. The docs actually say that in the "Returns" section: "New Bitmap object"...

So, yes, you should cache the object and reuse it among your screens. It's not unusual to store the bitmap instances in statics that are accessed throughout the app.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜