How to convert a Drawable to a Bitmap?
来源:互联网 发布:权威的时尚杂志 知乎 编辑:程序博客网 时间:2024/05/17 21:41
原文:http://stackoverflow.com/questions/3035692/how-to-convert-a-drawable-to-a-bitmap
/** * This method returns a bitmap related to resource id. It is ready to use method, you can * use it by simply copying in your project. * * @param context Context of calling activity * @param drawableId Resource ID of bitmap drawable * @return Bitmap whose resource id was passed to method. */public static Bitmap getBitmapFromDrawableId(Context context,int drawableId){ Bitmap bitmap = null; try { BitmapDrawable drawable = (BitmapDrawable)context.getResources().getDrawable(drawableId); bitmap = drawable.getBitmap(); } catch (Exception e) { e.printStackTrace(); } return bitmap;}/** * This method returns a bitmap related to drawable. It is ready to use method, you can * use it by simply copying in your project. * * @param drawable Drawable resource of image * @return Bitmap whose resource id was passed to method. */public static Bitmap getBitmapFromDrawable(Drawable drawable){ Bitmap bitmap = null; try { BitmapDrawable bitmapDrawable = (BitmapDrawable)drawable; bitmap = bitmapDrawable.getBitmap(); } catch (Exception e) { e.printStackTrace(); } return bitmap;}
- How to convert a Drawable to a Bitmap?
- How to convert a String to DateTime
- Android: Failed to convert @drawable/picture into a drawable
- Android: failed to convert @drawable/picture into a drawable
- Rendering Problems:Failed to convert .jpg in to a drawable
- How to convert a date to internal or external format?
- How to convert a type object from unshared to shared.
- How to convert a latex to pdf file
- Swift: How to convert a String to UInt8 array?
- How to convert a Map to List in Java?
- How to convert a list of tensors into a tensor
- How can I convert printStackTrace message to a string?
- Conclusion: How to create a color Bitmap with CreateCompatibleBitmap
- How to convert a simple DLINQ Query to a data set object
- Android: how to convert whole ImageView to Bitmap?
- convert a string to XmlElement
- Convert a vector to matrix
- Convert a Number to Hexadecimal
- js获取 本周,本月,本季度,本年,上月,上周,上季度,去年
- 随想
- mashang马尚的空间(百度空间)
- C++内存分配秘籍—new,malloc,GlobalAlloc详解
- 南京市区枪击案疑系双方开车斗气引发(图)-开车斗气-枪击-南京枪击案
- How to convert a Drawable to a Bitmap?
- ApiDemos-----app----Activity---ToggleButton控件的学习
- SoftReference、Weak Reference和PhantomRefrence分析和比较
- Nginx源代码分析-connection处理 【转】
- Java的基本类型
- VC命令行编译参数介绍
- 开始使用Mac OS X——写给Mac新人
- 《Unix & Linux 大学教程》 - 第二十二章(二) 学习笔记
- JAVA正则忽略大小写