static Bitmap generateBitmap(Bitmap bm, int width, int height) {
if (bm == null) {
return null;
}
bm.setDensity(DisplayMetrics.DENSITY_DEVICE);
if (width <= 0 || height <= 0
|| (bm.getWidth() == width && bm.getHeight() == height)) {
return bm;
}
// This is the final bitmap we want to return.
try {
Bitmap newbm = Bitmap.createBitmap(width, height, Bitmap.Config.ARGB_8888);
newbm.setDensity(DisplayMetrics.DENSITY_DEVICE);
Canvas c = new Canvas(newbm);
Rect targetRect = new Rect();
targetRect.right = bm.getWidth();
targetRect.bottom = bm.getHeight();
int deltaw = width - targetRect.right;
int deltah = height - targetRect.bottom;
if (deltaw > 0 || deltah > 0) {
generateBitmap 函数分析
最新推荐文章于 2023-02-13 17:59:50 发布