/**
* 从一个view创建Bitmap。
* 注意点:绘制之前要清掉 View 的焦点,因为焦点可能会改变一个 View 的 UI 状态。
* 来源:https://github.com/tyrantgit/ExplosionField
*
* @param view 传入一个 View,会获取这个 View 的内容创建 Bitmap。
* @param scale 缩放比例,对创建的 Bitmap 进行缩放,数值支持从 0 到 1。
*/
public static Bitmap createBitmapFromView(View view, float scale) {
if (view instanceof ImageView) {
Drawable drawable = ((ImageView) view).getDrawable();
if (drawable != null && drawable instanceof BitmapDrawable) {
return ((BitmapDrawable) drawable).getBitmap();
}
}
view.clearFocus();
Bitmap bitmap = createBitmapSafely((int) (view.getWidth() * scale),
(int) (view.getHeight() * scale), Bitmap.Config.ARGB_8888, 1);
if (bitmap != null) {
synchronized (sCanvas) {
Canvas canvas = sCanvas;
canvas.setBitmap(bitmap);
canvas.save();
canvas.drawColor(Color.WHITE); // 防止 View 上面有些区域空白导致最终 Bitmap 上有些区域变黑
canvas.scale(scale, scale);
view.draw(canvas);
canvas.restore();
canvas.setBitmap(null);
}
}
return bitmap;
}
java类android.graphics.drawable.BitmapDrawable的实例源码
QMUIDrawableHelper.java 文件源码
项目:QMUI_Android
阅读 63
收藏 0
点赞 0
评论 0
BitmapUtils.java 文件源码
项目:QiangHongBao
阅读 63
收藏 0
点赞 0
评论 0
/**
* 从视图创建位图
* @param view
* @return
*/
public static Bitmap createBitmapFromView(View view) {
if (view instanceof ImageView) {
Drawable drawable = ((ImageView) view).getDrawable();
if (drawable != null && drawable instanceof BitmapDrawable) {
return ((BitmapDrawable) drawable).getBitmap();
}
}
view.clearFocus();
Bitmap bitmap = createBitmapSafely(view.getWidth(),
view.getHeight(), Bitmap.Config.ARGB_8888, 1);
if (bitmap != null) {
synchronized (sCanvas) {
Canvas canvas = sCanvas;
canvas.setBitmap(bitmap);
view.draw(canvas);
canvas.setBitmap(null);
}
}
return bitmap;
}
OrderDialogFragment.java 文件源码
项目:From-design-to-Android-part1
阅读 42
收藏 0
点赞 0
评论 0
private Drawable createProductImageDrawable(Product product) {
final ShapeDrawable background = new ShapeDrawable();
background.setShape(new OvalShape());
background.getPaint().setColor(ContextCompat.getColor(getContext(), product.color));
final BitmapDrawable bitmapDrawable = new BitmapDrawable(getResources(),
BitmapFactory.decodeResource(getResources(), product.image));
final LayerDrawable layerDrawable = new LayerDrawable
(new Drawable[]{background, bitmapDrawable});
final int padding = (int) getResources().getDimension(R.dimen.spacing_huge);
layerDrawable.setLayerInset(1, padding, padding, padding, padding);
return layerDrawable;
}
MFBImageInfo.java 文件源码
项目:MyFlightbookAndroid
阅读 31
收藏 0
点赞 0
评论 0
protected void onPostExecute(Drawable d) {
if (d != null) {
if (imgView != null)
imgView.setImageDrawable(d);
BitmapDrawable bd = (BitmapDrawable) d;
Bitmap bmp = bd.getBitmap();
ByteArrayOutputStream s = new ByteArrayOutputStream();
bmp.compress(Bitmap.CompressFormat.JPEG, 100, s);
if (mFIsThumbnail)
m_imgThumb = s.toByteArray();
else
m_imgData = s.toByteArray();
if (m_icc != null)
m_icc.imgCompleted(MFBImageInfo.this);
}
}
Utilities.java 文件源码
项目:SimpleUILauncher
阅读 36
收藏 0
点赞 0
评论 0
/**
* Badges the provided icon with the user badge if required.
*/
public static Bitmap badgeIconForUser(Bitmap icon, UserHandleCompat user, Context context) {
if (Utilities.ATLEAST_LOLLIPOP && user != null
&& !UserHandleCompat.myUserHandle().equals(user)) {
BitmapDrawable drawable = new FixedSizeBitmapDrawable(icon);
Drawable badged = context.getPackageManager().getUserBadgedIcon(
drawable, user.getUser());
if (badged instanceof BitmapDrawable) {
return ((BitmapDrawable) badged).getBitmap();
} else {
return createIconBitmap(badged, context);
}
} else {
return icon;
}
}
RoundImageView.java 文件源码
项目:andcouchbaseentity
阅读 50
收藏 0
点赞 0
评论 0
@Override
protected void onDraw(Canvas canvas) {
Drawable drawable = getDrawable();
if (drawable instanceof BitmapDrawable) {
RectF rectF = new RectF(drawable.getBounds());
int restoreCount = canvas.saveLayer(rectF, null, Canvas.ALL_SAVE_FLAG);
getImageMatrix().mapRect(rectF);
Paint paint = ((BitmapDrawable) drawable).getPaint();
paint.setAntiAlias(true);
paint.setColor(0xff000000);
canvas.drawARGB(0, 0, 0, 0);
canvas.drawRoundRect(rectF, RADIUS, RADIUS, paint);
Xfermode restoreMode = paint.getXfermode();
paint.setXfermode(new PorterDuffXfermode(PorterDuff.Mode.SRC_IN));
super.onDraw(canvas);
// Restore paint and canvas
paint.setXfermode(restoreMode);
canvas.restoreToCount(restoreCount);
} else {
super.onDraw(canvas);
}
}
ImageFrameCustomView.java 文件源码
项目:ImageFrame
阅读 34
收藏 0
点赞 0
评论 0
public void startImageFrame(final ImageFrameHandler imageFrameHandler) {
if (this.imageFrameHandler == null) {
this.imageFrameHandler = imageFrameHandler;
}else{
this.imageFrameHandler.stop();
this.imageFrameHandler = imageFrameHandler;
}
imageFrameHandler.setOnImageLoaderListener(new ImageFrameHandler.OnImageLoadListener() {
@Override
public void onImageLoad(BitmapDrawable drawable) {
ViewCompat.setBackground(ImageFrameCustomView.this, drawable);
}
@Override
public void onPlayFinish() {
}
});
post(new Runnable() {
@Override
public void run() {
imageFrameHandler.start();
}
});
}
PhotoGalleryFragment.java 文件源码
项目:AndroidProgramming3e
阅读 33
收藏 0
点赞 0
评论 0
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setRetainInstance(true);
new FetchItemsTask().execute();
Handler responseHandler = new Handler();
mThumbnailDownloader = new ThumbnailDownloader<>(responseHandler);
mThumbnailDownloader.setThumbnailDownloadListener(
new ThumbnailDownloader.ThumbnailDownloadListener<PhotoHolder>() {
@Override
public void onThumbnailDownloaded(PhotoHolder photoHolder, Bitmap bitmap) {
Drawable drawable = new BitmapDrawable(getResources(), bitmap);
photoHolder.bindDrawable(drawable);
}
}
);
mThumbnailDownloader.start();
mThumbnailDownloader.getLooper();
Log.i(TAG, "Background thread started");
}
ColorizedCardView.java 文件源码
项目:Hands-On-Android-UI-Development
阅读 43
收藏 0
点赞 0
评论 0
private Bitmap renderDrawable(final Drawable drawable) {
if (drawable instanceof BitmapDrawable) {
return ((BitmapDrawable) drawable).getBitmap();
}
final Rect bounds = drawable.getBounds();
final Bitmap bitmap = Bitmap.createBitmap(
bounds.width(),
bounds.height(),
Bitmap.Config.ARGB_8888
);
final Canvas canvas = new Canvas(bitmap);
canvas.translate(-bounds.left, -bounds.top);
drawable.draw(canvas);
return bitmap;
}
SpanUtils.java 文件源码
项目:HeadlineNews
阅读 37
收藏 0
点赞 0
评论 0
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;
}
SurroundTestFragment.java 文件源码
项目:CXJPadProject
阅读 42
收藏 0
点赞 0
评论 0
@OnClick({R.id.start, R.id.red_line, R.id.gray_line})
public void onViewClicked(View view) {
switch (view.getId()) {
case R.id.start:
Bitmap bp = pint1.createSnapshoot();
Drawable dw = new BitmapDrawable(getResources(),bp);
im.setImageDrawable(dw);
break;
case R.id.red_line:
break;
case R.id.gray_line:
break;
}
}
ImageUtils.java 文件源码
项目:LJFramework
阅读 43
收藏 0
点赞 0
评论 0
/**
* drawable转bitmap
*
* @param drawable drawable对象
* @return bitmap
*/
public static Bitmap drawable2Bitmap(Drawable drawable) {
if (drawable instanceof BitmapDrawable) {
return ((BitmapDrawable) drawable).getBitmap();
} else if (drawable instanceof NinePatchDrawable) {
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;
} else {
return null;
}
}
LetterTileProvider.java 文件源码
项目:chips-input-layout
阅读 37
收藏 0
点赞 0
评论 0
/**
* 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;
}
PicPopupWindow.java 文件源码
项目:PictureShow
阅读 36
收藏 0
点赞 0
评论 0
private PicPopupWindow(Context context) {
mContext = context;
mInflater = (LayoutInflater) mContext
.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
mPopupContent = (ViewGroup) mInflater.inflate(
R.layout.popup_window_list, null);
mPopupItemContent = (ViewGroup) mPopupContent
.findViewById(R.id.popup_window_item_content);
title = (TextView) mPopupContent
.findViewById(R.id.popup_window_title_text);
mPopupWindow = new PopupWindow(mPopupContent,
LayoutParams.MATCH_PARENT, LayoutParams.WRAP_CONTENT);
mPopupWindow.setFocusable(true);
mPopupWindow.setBackgroundDrawable(new BitmapDrawable());
mPopupWindow.setOnDismissListener(new OnDismissListener() {
@Override
public void onDismiss() {
// TODO Auto-generated method stub
resetItemByTag(setTag);
if (mAnimationListener != null) {
mAnimationListener.doAnimation(false);
}
}
});
mPopupWindow.setAnimationStyle(R.style.popup_window_animation);
}
BlurUtils.java 文件源码
项目:letv
阅读 44
收藏 0
点赞 0
评论 0
@TargetApi(Build.VERSION_CODES.JELLY_BEAN)
public static void blurAdvanced(Context context, Bitmap bkg, View view) {
if (bkg != null) {
Bitmap overlay = Bitmap.createBitmap(bkg.getWidth(), bkg.getHeight(), Config.ARGB_8888);
Canvas canvas = new Canvas(overlay);
Paint paint = new Paint();
paint.setFlags(2);
canvas.drawBitmap(bkg, 0.0f, 0.0f, paint);
overlay = FastBlur.doBlur(overlay, (int) 12.0f, true);
if (LetvUtils.getSDKVersion() >= 16) {
view.setBackground(new BitmapDrawable(context.getResources(), overlay));
} else {
view.setBackgroundDrawable(new BitmapDrawable(context.getResources(), overlay));
}
}
}
BitmapFragment.java 文件源码
项目:okwallet
阅读 39
收藏 0
点赞 0
评论 0
@Override
public Dialog onCreateDialog(final Bundle savedInstanceState) {
final Bundle args = getArguments();
final BitmapDrawable bitmap = new BitmapDrawable(getResources(), (Bitmap) args.getParcelable(KEY_BITMAP));
bitmap.setFilterBitmap(false);
final Dialog dialog = new Dialog(activity);
dialog.requestWindowFeature(Window.FEATURE_NO_TITLE);
dialog.setContentView(R.layout.bitmap_dialog);
dialog.setCanceledOnTouchOutside(true);
final ImageView imageView = (ImageView) dialog.findViewById(R.id.bitmap_dialog_image);
imageView.setImageDrawable(bitmap);
imageView.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(final View v) {
dismiss();
}
});
return dialog;
}
PersonalPopupWindow.java 文件源码
项目:YiZhi
阅读 38
收藏 0
点赞 0
评论 0
public PersonalPopupWindow(Context context) {
super(null, ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT, true);
mContext = context;
//设置点击空白处消失
setTouchable(true);
setOutsideTouchable(true);
setClippingEnabled(false);
WindowManager wm = (WindowManager) mContext.getSystemService(Context.WINDOW_SERVICE);
int w = wm.getDefaultDisplay().getWidth();
int h = wm.getDefaultDisplay().getHeight();
Bitmap bitmap = Bitmap.createBitmap(w, h, Bitmap.Config.ARGB_8888);
bitmap.eraseColor(Color.parseColor("#88000000"));//填充颜色
setBackgroundDrawable(new BitmapDrawable(context.getResources(), bitmap));
initView();
}
PlaneDrawable.java 文件源码
项目:DaiGo
阅读 40
收藏 0
点赞 0
评论 0
private void getBitmaps(Context context) {
BitmapDrawable drawable1 = (BitmapDrawable) context.getResources().getDrawable(R.mipmap.bga_refresh_loading01);
drawableMinddleWidth = drawable1.getMinimumWidth() / 2;
bitmaps.add(drawable1.getBitmap());
bitmaps.add(((BitmapDrawable) context.getResources().getDrawable(R.mipmap.bga_refresh_loading02)).getBitmap());
bitmaps.add(((BitmapDrawable) context.getResources().getDrawable(R.mipmap.bga_refresh_loading03)).getBitmap());
bitmaps.add(((BitmapDrawable) context.getResources().getDrawable(R.mipmap.bga_refresh_loading04)).getBitmap());
bitmaps.add(((BitmapDrawable) context.getResources().getDrawable(R.mipmap.bga_refresh_loading05)).getBitmap());
bitmaps.add(((BitmapDrawable) context.getResources().getDrawable(R.mipmap.bga_refresh_loading06)).getBitmap());
bitmaps.add(((BitmapDrawable) context.getResources().getDrawable(R.mipmap.bga_refresh_loading07)).getBitmap());
bitmaps.add(((BitmapDrawable) context.getResources().getDrawable(R.mipmap.bga_refresh_loading08)).getBitmap());
bitmaps.add(((BitmapDrawable) context.getResources().getDrawable(R.mipmap.bga_refresh_loading09)).getBitmap());
bitmaps.add(((BitmapDrawable) context.getResources().getDrawable(R.mipmap.bga_refresh_loading10)).getBitmap());
bitmaps.add(((BitmapDrawable) context.getResources().getDrawable(R.mipmap.bga_refresh_loading11)).getBitmap());
bitmaps.add(((BitmapDrawable) context.getResources().getDrawable(R.mipmap.bga_refresh_loading12)).getBitmap());
}
ImageWorker.java 文件源码
项目:SuperSelector
阅读 38
收藏 0
点赞 0
评论 0
/**
* Once the image is processed, associates it to the imageView
*/
@Override
protected void onPostExecute(BitmapDrawable value) {
//BEGIN_INCLUDE(complete_background_work)
// if cancel was called on this task or the "exit early" flag is set then we're done
if (isCancelled() || mExitTasksEarly) {
value = null;
}
final ImageView imageView = getAttachedImageView();
if (value != null && imageView != null) {
// if (BuildConfig.DEBUG) {
// Log.d(TAG, "onPostExecute - setting bitmap");
// }
setImageDrawable(imageView, value);
}
//END_INCLUDE(complete_background_work)
}
ResultActivity.java 文件源码
项目:PXLSRT
阅读 35
收藏 0
点赞 0
评论 0
private void processSavePicture(String directory) {
File file = new File(new StringBuilder()
.append(Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_PICTURES))
.append(File.separator)
.append(directory)
.append(File.separator)
.append(RESULT_FNAME_PREFIX)
.append(System.currentTimeMillis())
.append(PrefUtils.getImageFormatPref(getApplicationContext()))
.toString());
if (!file.getParentFile().exists()) {
file.mkdirs();
}
try {
presenter.saveResultPicture(new FileOutputStream(file),
((BitmapDrawable) ivResult.getDrawable()).getBitmap(),
PrefUtils.getImageQualityPref(getApplicationContext()));
presenter.setPath(file.getAbsolutePath());
} catch (IOException e) {
e.printStackTrace();
}
}
BoxingFrescoLoader.java 文件源码
项目:GitHub
阅读 33
收藏 0
点赞 0
评论 0
private Drawable createDrawableFromFetchedResult(Context context, CloseableImage image) {
if (image instanceof CloseableStaticBitmap) {
CloseableStaticBitmap closeableStaticBitmap = (CloseableStaticBitmap) image;
BitmapDrawable bitmapDrawable = createBitmapDrawable(context, closeableStaticBitmap.getUnderlyingBitmap());
return (closeableStaticBitmap.getRotationAngle() != 0 && closeableStaticBitmap.getRotationAngle() != -1 ? new OrientedDrawable(bitmapDrawable, closeableStaticBitmap.getRotationAngle()) : bitmapDrawable);
} else if (image instanceof CloseableAnimatedImage) {
AnimatedDrawableFactory animatedDrawableFactory = Fresco.getImagePipelineFactory().getAnimatedFactory().getAnimatedDrawableFactory(context);
if (animatedDrawableFactory != null) {
AnimatedDrawable animatedDrawable = (AnimatedDrawable) animatedDrawableFactory.create(image);
if (animatedDrawable != null) {
return animatedDrawable;
}
}
}
throw new UnsupportedOperationException("Unrecognized image class: " + image);
}
MultiColorPickerView.java 文件源码
项目:ColorPickerView
阅读 36
收藏 0
点赞 0
评论 0
private int getColorFromBitmap(float x, float y) {
if (paletteDrawable == null) return 0;
Matrix invertMatrix = new Matrix();
palette.getImageMatrix().invert(invertMatrix);
float[] mappedPoints = new float[]{x, y};
invertMatrix.mapPoints(mappedPoints);
if (palette.getDrawable() != null && palette.getDrawable() instanceof BitmapDrawable &&
mappedPoints[0] > 0 && mappedPoints[1] > 0 &&
mappedPoints[0] < palette.getDrawable().getIntrinsicWidth() && mappedPoints[1] < palette.getDrawable().getIntrinsicHeight()) {
invalidate();
return ((BitmapDrawable) palette.getDrawable()).getBitmap().getPixel((int) mappedPoints[0], (int) mappedPoints[1]);
}
return 0;
}
RichEditor.java 文件源码
项目:BBSSDK-for-Android
阅读 39
收藏 0
点赞 0
评论 0
private Bitmap toBitmap(Drawable drawable) {
if (drawable instanceof BitmapDrawable) {
return ((BitmapDrawable) drawable).getBitmap();
}
int width = drawable.getIntrinsicWidth();
width = width > 0 ? width : 1;
int height = drawable.getIntrinsicHeight();
height = height > 0 ? height : 1;
Bitmap bitmap = Bitmap.createBitmap(width, height, Bitmap.Config.ARGB_8888);
Canvas canvas = new Canvas(bitmap);
drawable.setBounds(0, 0, canvas.getWidth(), canvas.getHeight());
drawable.draw(canvas);
return bitmap;
}
CircleImageView.java 文件源码
项目:TripBuyer
阅读 31
收藏 0
点赞 0
评论 0
private Bitmap getBitmapFromDrawable(Drawable drawable) {
if (drawable == null) {
return null;
}
if (drawable instanceof BitmapDrawable) {
return ((BitmapDrawable) drawable).getBitmap();
}
try {
Bitmap bitmap;
if (drawable instanceof ColorDrawable) {
bitmap = Bitmap.createBitmap(COLORDRAWABLE_DIMENSION, COLORDRAWABLE_DIMENSION, BITMAP_CONFIG);
} else {
bitmap = Bitmap.createBitmap(drawable.getIntrinsicWidth(), drawable.getIntrinsicHeight(), BITMAP_CONFIG);
}
Canvas canvas = new Canvas(bitmap);
drawable.setBounds(0, 0, canvas.getWidth(), canvas.getHeight());
drawable.draw(canvas);
return bitmap;
} catch (OutOfMemoryError e) {
return null;
}
}
DrawableUtils.java 文件源码
项目:MusicX-music-player
阅读 71
收藏 0
点赞 0
评论 0
public static Bitmap drawableToBitmap(@NonNull 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.RGB_565); // Single color bitmap will be created of 1x1 pixel
} else {
bitmap = Bitmap.createBitmap(drawable.getIntrinsicWidth(), drawable.getIntrinsicHeight(), Bitmap.Config.RGB_565);
}
Canvas canvas = new Canvas(bitmap);
drawable.setBounds(0, 0, canvas.getWidth(), canvas.getHeight());
drawable.draw(canvas);
return bitmap;
}
Util.java 文件源码
项目:content-farm-blocker-android
阅读 34
收藏 0
点赞 0
评论 0
public static Bitmap drawableToBitmap(Drawable drawable) {
if (drawable instanceof BitmapDrawable) {
return ((BitmapDrawable) drawable).getBitmap();
}
final int width = !drawable.getBounds().isEmpty() ? drawable
.getBounds().width() : drawable.getIntrinsicWidth();
final int height = !drawable.getBounds().isEmpty() ? drawable
.getBounds().height() : drawable.getIntrinsicHeight();
final Bitmap bitmap = Bitmap.createBitmap(width <= 0 ? 1 : width,
height <= 0 ? 1 : height, Bitmap.Config.ARGB_8888);
Canvas canvas = new Canvas(bitmap);
drawable.setBounds(0, 0, canvas.getWidth(), canvas.getHeight());
drawable.draw(canvas);
return bitmap;
}
ContextUtils.java 文件源码
项目:markor
阅读 39
收藏 0
点赞 0
评论 0
public Bitmap getBitmapFromDrawable(int drawableId) {
Bitmap bitmap = null;
Drawable drawable = ContextCompat.getDrawable(_context, drawableId);
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP && (drawable instanceof VectorDrawable || drawable instanceof VectorDrawableCompat)) {
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.LOLLIPOP) {
drawable = (DrawableCompat.wrap(drawable)).mutate();
}
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);
} else if (drawable instanceof BitmapDrawable) {
bitmap = ((BitmapDrawable) drawable).getBitmap();
}
return bitmap;
}
CircleImageView.java 文件源码
项目:yyox
阅读 33
收藏 0
点赞 0
评论 0
private Bitmap getBitmapFromDrawable(Drawable drawable) {
if (drawable == null) {
return null;
}
if (drawable instanceof BitmapDrawable) {
return ((BitmapDrawable) drawable).getBitmap();
}
try {
Bitmap bitmap;
if (drawable instanceof ColorDrawable) {
bitmap = Bitmap.createBitmap(COLORDRAWABLE_DIMENSION, COLORDRAWABLE_DIMENSION, BITMAP_CONFIG);
} else {
bitmap = Bitmap.createBitmap(drawable.getIntrinsicWidth(), drawable.getIntrinsicHeight(), BITMAP_CONFIG);
}
Canvas canvas = new Canvas(bitmap);
drawable.setBounds(0, 0, canvas.getWidth(), canvas.getHeight());
drawable.draw(canvas);
return bitmap;
} catch (OutOfMemoryError e) {
return null;
}
}
CircleImageView.java 文件源码
项目:MultipleItemPage
阅读 46
收藏 0
点赞 0
评论 0
private Bitmap getBitmapFromDrawable(Drawable drawable) {
if (drawable == null) {
return null;
}
if (drawable instanceof BitmapDrawable) {
return ((BitmapDrawable) drawable).getBitmap();
}
try {
Bitmap bitmap;
if (drawable instanceof ColorDrawable) {
bitmap = Bitmap.createBitmap(COLORDRAWABLE_DIMENSION, COLORDRAWABLE_DIMENSION, BITMAP_CONFIG);
} else {
bitmap = Bitmap.createBitmap(drawable.getIntrinsicWidth(), drawable.getIntrinsicHeight(), BITMAP_CONFIG);
}
Canvas canvas = new Canvas(bitmap);
drawable.setBounds(0, 0, canvas.getWidth(), canvas.getHeight());
drawable.draw(canvas);
return bitmap;
} catch (OutOfMemoryError e) {
return null;
}
}
ACache.java 文件源码
项目:ImitateZHRB
阅读 42
收藏 0
点赞 0
评论 0
@SuppressWarnings("deprecation")
private static Drawable bitmap2Drawable(Bitmap bm) {
if (bm == null) {
return null;
}
return new BitmapDrawable(bm);
}