Android中Bitmap, Drawable, Byte,ID之间的转化
2014-04-12 14:08
441 查看
Android中Bitmap, Drawable, Byte,ID之间的转化 博客分类: Android 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); / Bitmap → Drawable public static Drawable convertBitmap2Drawable(Bitmap bitmap) { BitmapDrawable bd = new BitmapDrawable(bitmap); // 因为BtimapDrawable是Drawable的子类,最终直接使用bd对象即可。 return bd; } 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 = activity.getResources().getDrawable(R.drawable.icon); 6.id转化成Bitmap Bitmap bitmap = BitmapFactory. decodeResource (Resources res, int id) 转:http://xiechengfa.iteye.com/blog/1117611
相关文章推荐
- Android中Bitmap, Drawable, Byte,ID之间的转化
- Android中Bitmap, Drawable, Byte,ID之间的转化
- Android中Bitmap, Drawable, Byte,ID之间的转化
- Android中Bitmap, Drawable, Byte,ID之间的转化
- Android中Bitmap, Drawable, Byte,ID之间的转化
- Android中Bitmap, Drawable, Byte,ID之间的转化
- Android中Bitmap, Drawable, Byte,ID之间的转化
- Android中Bitmap, Drawable, Byte,ID之间的转化
- Android中Bitmap, Drawable, Byte,ID之间的转化
- Android中Bitmap, Drawable, Byte,ID之间的转化
- Android中Bitmap, Drawable, Byte,ID之间的转化
- Android中Bitmap, Drawable, Byte,ID之间的转化
- Android中Bitmap, Drawable, Byte,ID之间的转化
- Android中Bitmap, Drawable, Byte,ID之间的转化
- Android中Bitmap, Drawable, Byte,ID之间的转化
- Android中Bitmap, ID,Drawable, Byte之间的转换
- Android中Bitmap, Drawable, Byte之间的转化
- Android中Bitmap, Drawable, Byte之间的转化
- android----Bitmap / Drawable / byte[] 之间相互转化
- Android中Bitmap, Drawable, Byte之间的转化