现在的位置: 首页 > 综合 > 正文

android bitmap drawable byte[]

2013年12月10日 ⁄ 综合 ⁄ 共 608字 ⁄ 字号 评论关闭

 转自:http://bingtian.iteye.com/blog/642128

从view中获得imageview   获得drawable     
	ImageView iv=(ImageView) view.findViewById(R.id.la_image);
	Drawable drawable=iv.getDrawable();
ava.lang.Object
   ↳ 	android.graphics.drawable.Drawable
  	   ↳ 	android.graphics.drawable.BitmapDrawable

drawable   转 bitmap
	BitmapDrawable bd=(BitmapDrawable) drawable;
	Bitmap bm=bd.getBitmap();
bitma转成byte[]
	ByteArrayOutputStream baos = new ByteArrayOutputStream();
	bm.compress(Bitmap.CompressFormat.PNG, 100, baos);
	byte[] by=baos.toByteArray();
byte[]  转成bitmap
Bitmap bm=BitmapFactory.decodeByteArray(b, 0, b.length)

bitmap 转成drawable
Drawable drawable = new BitmapDrawable(bitmap);

 

抱歉!评论已关闭.