android 图片转换
2015-10-12 10:27
447 查看
1. Bitmap 转化为 byte
ByteArrayOutputStream out = new ByteArrayOutputStream();
bitmap.compress(Bitmap.CompressFormat.PNG, 100, out);
byte[] array= out.toByteArray();
2. byte转化为bitmap
Bitmap bitmap = BitmapFactory.decodeByteArray(data, 0, data.length);
3. bitmap转化为Drawable
Drawable drawable = new FastBitmapDrawable(bitmap);
4. Drawable转化为bitmap
a. BitmapDrawable, FastBitmapDrawable直接用getBitmap
b. 其他类型的Drawable用Canvas画到一个bitmap上
Canvas canvas = new Canvas(bitmap)
drawable.draw(canvas)
5.id转化graphic.drawable
Drawable drawable = getResources().getDrawable(R.drawable.icon);
6.id转化成Bitmap
Bitmap bitmap = BitmapFactory. decodeResource (Resources res, int id)
ByteArrayOutputStream out = new ByteArrayOutputStream();
bitmap.compress(Bitmap.CompressFormat.PNG, 100, out);
byte[] array= out.toByteArray();
2. byte转化为bitmap
Bitmap bitmap = BitmapFactory.decodeByteArray(data, 0, data.length);
3. bitmap转化为Drawable
Drawable drawable = new FastBitmapDrawable(bitmap);
4. Drawable转化为bitmap
a. BitmapDrawable, FastBitmapDrawable直接用getBitmap
b. 其他类型的Drawable用Canvas画到一个bitmap上
Canvas canvas = new Canvas(bitmap)
drawable.draw(canvas)
5.id转化graphic.drawable
Drawable drawable = getResources().getDrawable(R.drawable.icon);
6.id转化成Bitmap
Bitmap bitmap = BitmapFactory. decodeResource (Resources res, int id)
相关文章推荐
- Android-Universal-Image-Loader 图片异步加载类库的使用(超详细配置)
- Android开发总结笔记 SeekBar(滑块条) 1-1-13
- Android 轮番播放广告图片
- Android开发总结笔记 RatingBar(评分条) 1-1-12
- android 内存优化总结
- android inputreader 部分对event数据的处理
- Android不发版也能在线修Bug?——AndFix 框架
- Android串口通信demo(AS)
- Android MD5加签源代码算法
- android 自定义按钮,点击变色,圆角
- Android Studio插件开发
- Android通讯录联系人的读取、更新、插入、删除等方法
- Android开发之WebService
- Android进程间通讯之messenger
- android Button文本自动变大写解决办法
- 用 Maven 运行 MyBatis Generator(Running MyBatis Generator With Maven)《IT蓝豹》
- 【Android系列】之DOM、SAX、Pull解析XML
- 【Android Studio】Frameworks detected: Android framework is detected in the project Configure
- android开发:自定义ListView总结
- Android打开文件代码