本文整理匯總了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);
}
}
}
示例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;
}