Android Question Canvas Memory Usage

Discussion in 'Android Questions' started by Gary Milne, Mar 1, 2015.

  1. Gary Milne

    Gary Milne Active Member Licensed User

    From what I have read a canvas allocates memory when it is initialized that is equivalent to:

    Canvas Width * Canvas Height * 4bytes - On a Nexus 7 this would be 1920 * 1280 * 4 = 9.8Mb​

    If I load a 1Mb PNG file into the canvas, does the canvas object use 9.8Mb or 1Mb of memory.

    Thanks.
     
  2. Erel

    Erel Administrator Staff Member Licensed User

    Canvas draws on a mutable bitmap that it implicitly creates (assuming that you are not using Canvas.Initialize2).
    The memory required is approximately Width * Height * 4 bytes.

    This is also true for bitmaps that you load. When you load an image file the memory required depends on the width and height of the image.

    The canvas itself will always consume the same memory. You can draw 1000 bitmaps with Canvas.DrawBitmap and the canvas memory usage will be the same.
     
Loading...
  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice