private static Bitmap createDrawableBitmap(Drawable drawable) {
int width = drawable.getIntrinsicWidth();
int height = drawable.getIntrinsicHeight();
if (width <= 0 || height <= 0) {
return null;
}
float scale = Math.min(1.0f, ((float) MAX_IMAGE_SIZE) / ((float) (width * height)));
if ((drawable instanceof BitmapDrawable) && scale == 1.0f) {
return ((BitmapDrawable) drawable).getBitmap();
}
int bitmapWidth = (int) (((float) width) * scale);
int bitmapHeight = (int) (((float) height) * scale);
Bitmap bitmap = Bitmap.createBitmap(bitmapWidth, bitmapHeight, Config.ARGB_8888);
Canvas canvas = new Canvas(bitmap);
Rect existingBounds = drawable.getBounds();
int left = existingBounds.left;
int top = existingBounds.top;
int right = existingBounds.right;
int bottom = existingBounds.bottom;
drawable.setBounds(0, 0, bitmapWidth, bitmapHeight);
drawable.draw(canvas);
drawable.setBounds(left, top, right, bottom);
return bitmap;
}
SharedElementCallback.java 文件源码
java
阅读 46
收藏 0
点赞 0
评论 0
项目:letv
作者:
评论列表
文章目录