From 9b825aa0eec5f143cec4c3cfeff97ba8d3d9d093 Mon Sep 17 00:00:00 2001 From: Scott Main Date: Thu, 7 May 2009 11:59:14 -0700 Subject: [PATCH] AI 148470: add documentation about aapt image optimization BUG=1735176 Automated import of CL 148470 --- .../html/guide/topics/graphics/2d-graphics.jd | 15 ++++++++++++--- .../guide/topics/resources/resources-i18n.jd | 19 ++++++++++++++----- 2 files changed, 26 insertions(+), 8 deletions(-) diff --git a/docs/html/guide/topics/graphics/2d-graphics.jd b/docs/html/guide/topics/graphics/2d-graphics.jd index 1f62f3d0f3672..af584a23fbe5b 100644 --- a/docs/html/guide/topics/graphics/2d-graphics.jd +++ b/docs/html/guide/topics/graphics/2d-graphics.jd @@ -10,8 +10,8 @@ parent.link=index.html
  1. Drawables
      -
    1. Creating from resource images
    2. -
    3. Creating from resource XML
    4. +
    5. Creating from resource images
    6. +
    7. Creating from resource XML
  2. ShapeDrawable
  3. @@ -59,6 +59,15 @@ From there, you can reference it from your code or your XML layout. Either way, it is referred using a resource ID, which is the file name without the file type extension (E.g., my_image.png is referenced as my_image).

    +

    Note: Image resources placed in res/drawable/ may be +automatically optimized with lossless image compression by the +aapt tool. For example, a true-color PNG that does +not require more than 256 colors may be converted to an 8-bit PNG with a color palette. This +will result in an image of equal quality but which requires less memory. So be aware that the +image binaries placed in this directory can change during the build. If you plan on reading +an image as a bit stream in order to convert it to a bitmap, put your images in the res/raw/ +folder instead, where they will not be optimized.

    +

    Example code

    The following code snippet demonstrates how to build an {@link android.widget.ImageView} that uses an image from drawable resources and add it to the layout.

    @@ -90,7 +99,7 @@ Resources res = mContext.getResources(); Drawable myImage = res.getDrawable(R.drawable.my_image); -

    Caution: Each unique resource in your project can maintain only one +

    Note: Each unique resource in your project can maintain only one state, no matter how many different objects you may instantiate for it. For example, if you instantiate two Drawable objects from the same image resource, then change a property (such as the alpha) for one of the Drawables, then it will also affect the other. So when dealing with multiple instances of an image resource, diff --git a/docs/html/guide/topics/resources/resources-i18n.jd b/docs/html/guide/topics/resources/resources-i18n.jd index b1da4cd6584de..4bbb44ac5e5a2 100644 --- a/docs/html/guide/topics/resources/resources-i18n.jd +++ b/docs/html/guide/topics/resources/resources-i18n.jd @@ -111,21 +111,30 @@ the containing file.

    res/drawable/

    .png, .9.png, .jpg files that are compiled into the following Drawable resource subtypes:

    -

    To get a resource of this type, use Resource.getDrawable(id) -

    +

    To get a resource of this type, use mContext.getResources().getDrawable(R.drawable.imageId)

    +

    Note: Image resources placed in here may + be automatically optimized with lossless image compression by the + aapt tool. For example, a true-color PNG + that does not require more than 256 colors may be converted to an 8-bit PNG with a color palette. + This will result in an image of equal quality but which requires less memory. So be aware that the + image binaries placed in this directory can change during the build. If you plan on reading + an image as a bit stream in order to convert it to a bitmap, put your images in the + res/raw/ folder instead, where they will not be optimized.

    + res/layout/ XML files that are compiled into screen layouts (or part of a screen). - See Declaring Layout + See Declaring Layout. res/values/

    XML files that can be compiled into many kinds of resource.

    -

    Note: unlike the other res/ folders, this one +

    Note: Unlike the other res/ folders, this one can hold any number of files that hold descriptions of resources to create rather than the resources themselves. The XML element types control where these resources are placed under the R class.