Code example for Drawable

Methods: drawgetBoundsgetIntrinsicHeightgetIntrinsicWidthgetOpacitysetBounds

0
                    width = (int) (height * ratio);
                } 
 
                final Bitmap.Config c = icon.getOpacity() != PixelFormat.OPAQUE ?
                            Bitmap.Config.ARGB_8888 : Bitmap.Config.RGB_565;
                final Bitmap thumb = Bitmap.createBitmap(sIconWidth, sIconHeight, c);
                final Canvas canvas = sCanvas;
                canvas.setBitmap(thumb);
                // Copy the old bounds to restore them later 
                // If we were to do oldBounds = icon.getBounds(), 
                // the call to setBounds() that follows would 
                // change the same instance and we would lose the 
                // old bounds 
                sOldBounds.set(icon.getBounds());
                final int x = (sIconWidth - width) / 2;
                final int y = (sIconHeight - height) / 2;
                icon.setBounds(x, y, x + width, y + height);
                icon.draw(canvas);
                icon.setBounds(sOldBounds);
                icon = new FastBitmapDrawable(thumb);
            } else if (iconWidth < width && iconHeight < height) {
                final Bitmap.Config c = Bitmap.Config.ARGB_8888;
                final Bitmap thumb = Bitmap.createBitmap(sIconWidth, sIconHeight, c);
                final Canvas canvas = sCanvas;
                canvas.setBitmap(thumb);
                sOldBounds.set(icon.getBounds());
                final int x = (width - iconWidth) / 2;
                final int y = (height - iconHeight) / 2;
                icon.setBounds(x, y, x + iconWidth, y + iconHeight);
                icon.draw(canvas);
                icon.setBounds(sOldBounds);
                icon = new FastBitmapDrawable(thumb);
            } 
        } 
 
        return icon;
    } 
 
    /** 
     * Returns a Bitmap representing the thumbnail of the specified Bitmap. 
     * The size of the thumbnail is defined by the dimension 
     * android.R.dimen.launcher_application_icon_size. 
     * 
     * This method is not thread-safe and should be invoked on the UI thread only. 
     * 
     * @param bitmap The bitmap to get a thumbnail of. 
     * @param context The application's context. 
     * 
     * @return A thumbnail for the specified bitmap or the bitmap itself if the 
     *         thumbnail could not be created. 
     */