byte[] img_data;
//设置图片
ImageView imgExtendImageView1 = new ImageView(mContext);
imgExtendImageView1.setImageResource(R.drawable.test);
//设置尺寸
imgExtendImageView1.measure(MeasureSpec.makeMeasureSpec(0, MeasureSpec.UNSPECIFIED), MeasureSpec.makeMeasureSpec(0, MeasureSpec.UNSPECIFIED));
imgExtendImageView1.layout(0, 0, imgExtendImageView1.getMeasuredWidth(), imgExtendImageView1.getMeasuredHeight());
//得到 Bitmap
imgExtendImageView1.setDrawingCacheEnabled(true);
imgExtendImageView1.buildDrawingCache(true);
Bitmap obmp = imgExtendImageView1.getDrawingCache();
//压缩成PNG
final ByteArrayOutputStream os = new ByteArrayOutputStream();
obmp.compress(Bitmap.CompressFormat.PNG, 100, os);
//得到二进制数据
img_data = os.toByteArray();
imgExtendImageView1.setDrawingCacheEnabled(false);
转载请注明出处:http://blog.csdn.net/ztp800201/article/details/15809069