當前位置: 首頁>>代碼示例>>Java>>正文


Java BitmapDrawable.draw方法代碼示例

本文整理匯總了Java中android.graphics.drawable.BitmapDrawable.draw方法的典型用法代碼示例。如果您正苦於以下問題:Java BitmapDrawable.draw方法的具體用法?Java BitmapDrawable.draw怎麽用?Java BitmapDrawable.draw使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在android.graphics.drawable.BitmapDrawable的用法示例。


在下文中一共展示了BitmapDrawable.draw方法的2個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: dispatchDraw

import android.graphics.drawable.BitmapDrawable; //導入方法依賴的package包/類
/**
 * By overriding dispatchDraw, the BitmapDrawables of all the cells that were on the
 * screen before (but not after) the layout are drawn and animated off the screen.
 */
@Override
protected void dispatchDraw (Canvas canvas) {
    super.dispatchDraw(canvas);
    if (mCellBitmapDrawables.size() > 0) {
        for (BitmapDrawable bitmapDrawable: mCellBitmapDrawables) {
            bitmapDrawable.draw(canvas);
        }
    }
}
 
開發者ID:sdrausty,項目名稱:buildAPKsSamples,代碼行數:14,代碼來源:InsertionListView.java

示例2: centerCrop

import android.graphics.drawable.BitmapDrawable; //導入方法依賴的package包/類
/**
 * 居中剪切圖片
 */
public static Bitmap centerCrop(Resources res, Bitmap bitmap, int width, int height) {
    if (bitmap == null) {
        return null;
    }
    Bitmap result = Bitmap.createBitmap(width, height, Bitmap.Config.ARGB_8888);

    Matrix matrix = new Matrix();

    float scale;
    float dx = 0, dy = 0;

    final int dwidth = bitmap.getWidth();
    final int dheight = bitmap.getHeight();

    final int vwidth = width;
    final int vheight = height;

    if (dwidth * vheight > vwidth * dheight) {
        scale = (float) vheight / (float) dheight;
        dx = (vwidth - dwidth * scale) * 0.5f;
    } else {
        scale = (float) vwidth / (float) dwidth;
        dy = (vheight - dheight * scale) * 0.5f;
    }

    matrix.setScale(scale, scale);
    matrix.postTranslate(Math.round(dx), Math.round(dy));

    Canvas canvas = new Canvas(result);
    canvas.concat(matrix);
    BitmapDrawable bitmapDrawable = new BitmapDrawable(res, bitmap);
    bitmapDrawable.setBounds(0, 0, dwidth, dheight);
    bitmapDrawable.draw(canvas);

    return result;
}
 
開發者ID:angcyo,項目名稱:RLibrary,代碼行數:40,代碼來源:ImagePickerImageView.java


注:本文中的android.graphics.drawable.BitmapDrawable.draw方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。