获取资源文件 r.drawable中的图片转换为drawable、bitmap

简介:
复制代码
1、

Resources resources = mContext.getResources();
Drawable drawable = resources.getDrawable(R.drawable.a);
imageview.setBackground(drawable);

2、

Resources r = this.getContext().getResources();
Inputstream is = r.openRawResource(R.drawable.my_background_image);
BitmapDrawable  bmpDraw = new BitmapDrawable(is);
Bitmap bmp = bmpDraw.getBitmap();

3、

Bitmap bmp=BitmapFactory.decodeResource(r, R.drawable.icon);

Bitmap newb = Bitmap.createBitmap( 300, 300, Config.ARGB_8888 ); 

4、

InputStream is = getResources().openRawResource(R.drawable.icon);  

Bitmap mBitmap = BitmapFactory.decodeStream(is);

 
复制代码



相关文章
|
Android开发
Android获取Bitmap网络图片类型
Android获取Bitmap网络图片类型
|
Android开发
Android笔记:根据图片url获取bitmap或者drawable,然后再进行压缩处理
Android笔记:根据图片url获取bitmap或者drawable,然后再进行压缩处理
438 0
|
缓存
获取ImageView图片
//设置可以获取imageView缓存 imageView.setDrawingCacheEnabled(true); //然后通过getDrawingCache方法获取BitMap Bitmap drawingCache = imageView.
1131 0
|
Android开发
最新Android Glide4.0加载Gif图片到ImageView
最新Android Glide4.0加载Gif图片到ImageView 在我过去的文章里面,介绍了旧的Glide 3.0+的加载Gif图片方式(见文章:http://blog.csdn.net/zhangphil/article/details/45561983 ),现在Glide 4.0相较于Glide 3.0+发生了很大变化,现在给出一个新版Glide 4.0加载Gif图片的代码例子。
2509 0
|
Android开发
Android把Bitmap保存为PNG图像文件的简单方法(同步)
public static void saveBitmapAsPng(Bitmap bmp,File f) { try { FileOutputStream out = new FileOutputStream(f); bmp.
1370 0
|
XML Android开发 数据格式
Drawable解析4——StateListDrawable和AnimationDrawable
1、估计StateListDrawable是大家用的最多一个drawable了,所有的控件背景基本上都使用了StateListDrawable,以实现其在不同状态下显示不同的效果,例如按钮的按下、选中、默认、禁用等多种模式状态。
968 0
|
XML Android开发 数据格式
Drawable解析2——GradientDrawable、ShapeDrawable、InsetDrawable和RotateDrawable
继承上一节,这一节接着说四个子类 1、GradientDrawable表示一个渐变区域,可以实现线性渐变、发散渐变、和平铺渐变。
1242 0
|
XML Java Android开发
Drawable解析1——ColorDrawable、BitmapDrawable、ClipDrawabl和ScaleDrawable
Drawable资源是Android应用中使用最广泛的资源,它不仅可以使用各种格式的图片资源,也可以使用多种xml文件资源。
908 0
|
Java 大数据 Android开发
Android加载Gif和ImageView的通用解决方案:android-gif-drawable:GifTextView(2)
Android加载Gif和ImageView的通用解决方案:android-gif-drawable:GifTextView(2) 附录文章1简介了如何在Android中使用android-gif-drawable解决gif加载的问题。
1232 0