Code example for Bitmap

Methods: createScaledBitmapgetWidth

0
        if (mIconBitmap == null || mActualWidth == 0 || mActualHeight == 0) {
            clearImage(); 
            return; 
        } 
 
        if (mScalingExpected && mActualWidth != mIconBitmap.getWidth()) {
            scaleBitmap(); 
            // Don't scale the image every time something changes. 
            mScalingExpected = false;
        } 
 
        setImageBitmap(mIconBitmap);
 
        // After scaling, determine if we have empty space around the scaled image which we need to 
        // fill with the coloured background. If applicable, show it. 
        // We assume Favicons are still squares and only bother with the background if more than 3px 
        // of it would be displayed. 
        if (Math.abs(mIconBitmap.getWidth() - mActualWidth) > 3) {
            showBackground(); 
        } else { 
            hideBackground(); 
        } 
    } 
 
    private void scaleBitmap() { 
        // If the Favicon can be resized to fill the view exactly without an enlargment of more than 
        // a factor of two, do so. 
        int doubledSize = mIconBitmap.getWidth()*2;
        if (mActualWidth > doubledSize) {
            // If the view is more than twice the size of the image, just double the image size 
            // and do the rest with padding. 
            mIconBitmap = Bitmap.createScaledBitmap(mIconBitmap, doubledSize, doubledSize, true);
        } else { 
            // Otherwise, scale the image to fill the view. 
            mIconBitmap = Bitmap.createScaledBitmap(mIconBitmap, mActualWidth, mActualWidth, true);
        } 
    } 
 
    /** 
     * Helper method to display background of the dominant colour of the favicon to pad the remaining 
Stop searching for code, let great code find you!  Add Codota to your java IDE