本文整理汇总了Java中android.graphics.drawable.BitmapDrawable.getBitmap方法的典型用法代码示例。如果您正苦于以下问题:Java BitmapDrawable.getBitmap方法的具体用法?Java BitmapDrawable.getBitmap怎么用?Java BitmapDrawable.getBitmap使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类android.graphics.drawable.BitmapDrawable
的用法示例。
在下文中一共展示了BitmapDrawable.getBitmap方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: drawableToBitmap
import android.graphics.drawable.BitmapDrawable; //导入方法依赖的package包/类
/**
* Drawable转Bitmap方法
*/
public static Bitmap drawableToBitmap(Drawable drawable) {
Bitmap bitmap;
if (drawable instanceof BitmapDrawable) {
BitmapDrawable bitmapDrawable = (BitmapDrawable) drawable;
if (bitmapDrawable.getBitmap() != null) {
return bitmapDrawable.getBitmap();
}
}
if (drawable.getIntrinsicWidth() <= 0 || drawable.getIntrinsicHeight() <= 0) {
bitmap = Bitmap.createBitmap(1, 1,
Bitmap.Config.ARGB_8888);
} else {
bitmap = Bitmap.createBitmap(drawable.getIntrinsicWidth(), drawable.getIntrinsicHeight(),
Bitmap.Config.ARGB_8888);
}
Canvas canvas = new Canvas(bitmap);
drawable.setBounds(0, 0, canvas.getWidth(), canvas.getHeight());
drawable.draw(canvas);
return bitmap;
}
示例2: drawable2Bitmap
import android.graphics.drawable.BitmapDrawable; //导入方法依赖的package包/类
/**
* drawable转bitmap
*
* @param drawable drawable对象
* @return bitmap
*/
public static Bitmap drawable2Bitmap(final Drawable drawable) {
if (drawable instanceof BitmapDrawable) {
BitmapDrawable bitmapDrawable = (BitmapDrawable) drawable;
if (bitmapDrawable.getBitmap() != null) {
return bitmapDrawable.getBitmap();
}
}
Bitmap bitmap;
if (drawable.getIntrinsicWidth() <= 0 || drawable.getIntrinsicHeight() <= 0) {
bitmap = Bitmap.createBitmap(1, 1,
drawable.getOpacity() != PixelFormat.OPAQUE ? Bitmap.Config.ARGB_8888 : Bitmap.Config.RGB_565);
} else {
bitmap = Bitmap.createBitmap(drawable.getIntrinsicWidth(), drawable.getIntrinsicHeight(),
drawable.getOpacity() != PixelFormat.OPAQUE ? Bitmap.Config.ARGB_8888 : Bitmap.Config.RGB_565);
}
Canvas canvas = new Canvas(bitmap);
drawable.setBounds(0, 0, canvas.getWidth(), canvas.getHeight());
drawable.draw(canvas);
return bitmap;
}
示例3: drawableToBitMap
import android.graphics.drawable.BitmapDrawable; //导入方法依赖的package包/类
private static Bitmap drawableToBitMap(Drawable drawable) {
if (drawable == null) {
return null;
}
if (drawable instanceof BitmapDrawable) {
BitmapDrawable bitmapDrawable = ((BitmapDrawable) drawable);
return bitmapDrawable.getBitmap();
} else {
Bitmap bitmap = Bitmap.createBitmap(drawable.getIntrinsicWidth(), drawable.getIntrinsicHeight(),
drawable.getOpacity() != PixelFormat.OPAQUE ? Bitmap.Config.ARGB_8888 : Bitmap.Config.RGB_565);
Canvas canvas = new Canvas(bitmap);
drawable.setBounds(0, 0, drawable.getIntrinsicWidth(), drawable.getIntrinsicHeight());
drawable.draw(canvas);
return bitmap;
}
}
示例4: drawable2Bitmap
import android.graphics.drawable.BitmapDrawable; //导入方法依赖的package包/类
/**
* drawable转bitmap
*
* @param drawable drawable对象
* @return bitmap
*/
public static Bitmap drawable2Bitmap(final Drawable drawable) {
if (drawable instanceof BitmapDrawable) {
BitmapDrawable bitmapDrawable = (BitmapDrawable) drawable;
if (bitmapDrawable.getBitmap() != null) {
return bitmapDrawable.getBitmap();
}
}
Bitmap bitmap;
if (drawable.getIntrinsicWidth() <= 0 || drawable.getIntrinsicHeight() <= 0) {
bitmap = Bitmap.createBitmap(1, 1,
drawable.getOpacity() != PixelFormat.OPAQUE ? Bitmap.Config.ARGB_8888 : Bitmap.Config.RGB_565);
} else {
bitmap = Bitmap.createBitmap(drawable.getIntrinsicWidth(), drawable.getIntrinsicHeight(),
drawable.getOpacity() != PixelFormat.OPAQUE ? Bitmap.Config.ARGB_8888 : Bitmap.Config.RGB_565);
}
Canvas canvas = new Canvas(bitmap);
drawable.setBounds(0, 0, canvas.getWidth(), canvas.getHeight());
drawable.draw(canvas);
return bitmap;
}
示例5: drawable2Bitmap
import android.graphics.drawable.BitmapDrawable; //导入方法依赖的package包/类
private Bitmap drawable2Bitmap(final Drawable drawable) {
if (drawable instanceof BitmapDrawable) {
BitmapDrawable bitmapDrawable = (BitmapDrawable) drawable;
if (bitmapDrawable.getBitmap() != null) {
return bitmapDrawable.getBitmap();
}
}
Bitmap bitmap;
if (drawable.getIntrinsicWidth() <= 0 || drawable.getIntrinsicHeight() <= 0) {
bitmap = Bitmap.createBitmap(1, 1,
drawable.getOpacity() != PixelFormat.OPAQUE ? Bitmap.Config.ARGB_8888 : Bitmap.Config.RGB_565);
} else {
bitmap = Bitmap.createBitmap(drawable.getIntrinsicWidth(), drawable.getIntrinsicHeight(),
drawable.getOpacity() != PixelFormat.OPAQUE ? Bitmap.Config.ARGB_8888 : Bitmap.Config.RGB_565);
}
Canvas canvas = new Canvas(bitmap);
drawable.setBounds(0, 0, canvas.getWidth(), canvas.getHeight());
drawable.draw(canvas);
return bitmap;
}
示例6: drawable2Bitmap
import android.graphics.drawable.BitmapDrawable; //导入方法依赖的package包/类
private static Bitmap drawable2Bitmap(final Drawable drawable) {
if (drawable instanceof BitmapDrawable) {
BitmapDrawable bitmapDrawable = (BitmapDrawable) drawable;
if (bitmapDrawable.getBitmap() != null) {
return bitmapDrawable.getBitmap();
}
}
Bitmap bitmap;
if (drawable.getIntrinsicWidth() <= 0 || drawable.getIntrinsicHeight() <= 0) {
bitmap = Bitmap.createBitmap(1, 1,
drawable.getOpacity() != PixelFormat.OPAQUE ? Bitmap.Config.ARGB_8888 : Bitmap.Config.RGB_565);
} else {
bitmap = Bitmap.createBitmap(drawable.getIntrinsicWidth(), drawable.getIntrinsicHeight(),
drawable.getOpacity() != PixelFormat.OPAQUE ? Bitmap.Config.ARGB_8888 : Bitmap.Config.RGB_565);
}
Canvas canvas = new Canvas(bitmap);
drawable.setBounds(0, 0, canvas.getWidth(), canvas.getHeight());
drawable.draw(canvas);
return bitmap;
}
示例7: drawableToBitmap
import android.graphics.drawable.BitmapDrawable; //导入方法依赖的package包/类
private static Bitmap drawableToBitmap(Drawable drawable) {
Bitmap bitmap;
if (drawable instanceof BitmapDrawable) {
BitmapDrawable bitmapDrawable = (BitmapDrawable) drawable;
if (bitmapDrawable.getBitmap() != null) {
return bitmapDrawable.getBitmap();
}
}
if (drawable.getIntrinsicWidth() <= 0 || drawable.getIntrinsicHeight() <= 0) {
bitmap = Bitmap.createBitmap(1, 1, Bitmap.Config.ARGB_8888);
} else {
bitmap = Bitmap.createBitmap(drawable.getIntrinsicWidth(), drawable.getIntrinsicHeight(), Bitmap.Config.ARGB_8888);
}
Bitmap bitmapResized = Bitmap.createScaledBitmap(bitmap, 40, 40, false);
Canvas canvas = new Canvas(bitmapResized);
drawable.setBounds(0, 0, canvas.getWidth(), canvas.getHeight());
drawable.draw(canvas);
return bitmapResized;
}
示例8: initCofig
import android.graphics.drawable.BitmapDrawable; //导入方法依赖的package包/类
void initCofig(Context context, AttributeSet attrs) {
TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.CircleButton);
mColorNormal = a.getColor(R.styleable.CircleButton_pb_color, Color.parseColor("#ffffff"));
mColorChecked = a.getColor(R.styleable.CircleButton_pb_color_checked, Color.parseColor("#FFFF000D"));
mTextOn = a.getString(R.styleable.CircleButton_pb_text_on);
mTextOff = a.getString(R.styleable.CircleButton_pb_text_off);
BitmapDrawable bdmBackgroundChecked = (BitmapDrawable) a.getDrawable(R.styleable.CircleButton_pb_background_checked);
mCheckable = a.getBoolean(R.styleable.CircleButton_pb_checkable, false);
if (bdmBackgroundChecked != null)
mBackgroundChecked = bdmBackgroundChecked.getBitmap();
BitmapDrawable bdmBackground = (BitmapDrawable) a.getDrawable(R.styleable.CircleButton_pb_background);
if (bdmBackground != null)
mBackground = bdmBackground.getBitmap();
a.recycle();
}
示例9: drawableToBitmap
import android.graphics.drawable.BitmapDrawable; //导入方法依赖的package包/类
private static Bitmap drawableToBitmap(Drawable drawable) {
Bitmap bitmap;
if (drawable instanceof BitmapDrawable) {
BitmapDrawable bitmapDrawable = (BitmapDrawable) drawable;
if (bitmapDrawable.getBitmap() != null) {
return bitmapDrawable.getBitmap();
}
}
if (drawable.getIntrinsicWidth() <= 0 || drawable.getIntrinsicHeight() <= 0) {
bitmap = Bitmap.createBitmap(1, 1, Bitmap.Config.ARGB_8888); // Single color bitmap will be created of 1x1 pixel
} else {
bitmap = Bitmap.createBitmap(drawable.getIntrinsicWidth(), drawable.getIntrinsicHeight(), Bitmap.Config.ARGB_8888);
}
Canvas canvas = new Canvas(bitmap);
drawable.setBounds(0, 0, canvas.getWidth(), canvas.getHeight());
drawable.draw(canvas);
return bitmap;
}
示例10: drawableToBitmap
import android.graphics.drawable.BitmapDrawable; //导入方法依赖的package包/类
private static Bitmap drawableToBitmap(final Drawable drawable) {
if (drawable instanceof BitmapDrawable) {
final BitmapDrawable bitmapDrawable = (BitmapDrawable) drawable;
if (bitmapDrawable.getBitmap() != null) {
return bitmapDrawable.getBitmap();
}
}
final Bitmap bitmap;
if (drawable.getIntrinsicWidth() <= 0 || drawable.getIntrinsicHeight() <= 0) {
bitmap = Bitmap.createBitmap(FRAME_WIDTH, FRAME_HEIGHT, Bitmap.Config.ARGB_8888);
} else {
bitmap =
Bitmap.createBitmap(
drawable.getIntrinsicWidth(), drawable.getIntrinsicHeight(), Bitmap.Config.ARGB_8888);
}
final Canvas canvas = new Canvas(bitmap);
drawable.draw(canvas);
return bitmap;
}
示例11: drawableToBitmap
import android.graphics.drawable.BitmapDrawable; //导入方法依赖的package包/类
private static Bitmap drawableToBitmap (Drawable drawable) {
Bitmap bitmap = null;
if (drawable instanceof BitmapDrawable) {
BitmapDrawable bitmapDrawable = (BitmapDrawable) drawable;
if(bitmapDrawable.getBitmap() != null) {
return bitmapDrawable.getBitmap();
}
}
if(drawable.getIntrinsicWidth() <= 0 || drawable.getIntrinsicHeight() <= 0) {
bitmap = Bitmap.createBitmap(1, 1, Bitmap.Config.ARGB_8888); // Single color bitmap will be created of 1x1 pixel
} else {
bitmap = Bitmap.createBitmap(drawable.getIntrinsicWidth(), drawable.getIntrinsicHeight(), Bitmap.Config.ARGB_8888);
}
Canvas canvas = new Canvas(bitmap);
drawable.setBounds(0, 0, canvas.getWidth(), canvas.getHeight());
drawable.draw(canvas);
return bitmap;
}
示例12: drawableToBitmap
import android.graphics.drawable.BitmapDrawable; //导入方法依赖的package包/类
/**
* Creates a Bitmap object from a Drawable object.
*/
private static Bitmap drawableToBitmap(Drawable dr) {
// Attempt to retrieve any existing Bitmap, if possible
if (dr instanceof BitmapDrawable) {
BitmapDrawable bDr = (BitmapDrawable)dr;
if (bDr.getBitmap() != null) {
return bDr.getBitmap();
}
}
// Create a valid blank Bitmap
final Bitmap bitmap;
if (dr.getIntrinsicWidth() <= 0 || dr.getIntrinsicHeight() <= 0) {
// Single color bitmap will be create of 1x1 pixel
bitmap = Bitmap.createBitmap(1, 1, Bitmap.Config.ARGB_8888);
} else {
bitmap = Bitmap.createBitmap(dr.getIntrinsicWidth(),
dr.getIntrinsicHeight(), Bitmap.Config.ARGB_8888);
}
// Use our Canvas to draw the Drawable onto the Bitmap
Canvas canvas = new Canvas(bitmap);
dr.setBounds(0, 0, canvas.getWidth(), canvas.getHeight());
dr.draw(canvas);
return bitmap;
}
示例13: DirectionView
import android.graphics.drawable.BitmapDrawable; //导入方法依赖的package包/类
public DirectionView(Context context, AttributeSet attrs) {
super(context, attrs);
BitmapDrawable drawble = (BitmapDrawable) ContextCompat.getDrawable(getContext(),
R.drawable.direction);
image = drawble.getBitmap();
}
示例14: drawableToBitMap
import android.graphics.drawable.BitmapDrawable; //导入方法依赖的package包/类
private Bitmap drawableToBitMap(Drawable drawable) {
if (drawable instanceof BitmapDrawable) {
BitmapDrawable bitmapDrawable = ((BitmapDrawable) drawable);
return bitmapDrawable.getBitmap();
} else {
Bitmap bitmap = Bitmap.createBitmap(drawable.getIntrinsicWidth(), drawable.getIntrinsicHeight(), drawable.getOpacity() != PixelFormat.OPAQUE ? Bitmap.Config.ARGB_8888 : Bitmap.Config.RGB_565);
Canvas canvas = new Canvas(bitmap);
drawable.setBounds(0, 0, drawable.getIntrinsicWidth(),
drawable.getIntrinsicHeight());
drawable.draw(canvas);
return bitmap;
}
}
示例15: releaseTargetDrawable
import android.graphics.drawable.BitmapDrawable; //导入方法依赖的package包/类
private void releaseTargetDrawable() {
if (!frescoEnable && targetDrawable != null && targetDrawable instanceof BitmapDrawable) {
BitmapDrawable bitmapDrawable = (BitmapDrawable) targetDrawable;
Bitmap bitmap = bitmapDrawable.getBitmap();
if (!bitmap.isRecycled()) {
bitmap.isRecycled();
}
targetDrawable = null;
}
}