- 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);
得到ImageView的图片,压缩成PNG,并得到二进制流数据
最新推荐文章于 2021-05-29 03:31:12 发布