本文整理汇总了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;
}