质量压缩与二级采样
来源:互联网 发布:web安全工程师 知乎 编辑:程序博客网 时间:2024/06/02 04:12
public class MainActivity extends AppCompatActivity {
private ImageView imageview;
private ImageView imageview1;
private String path=”/sdcard/Download/aa.png”;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
imageview= (ImageView) findViewById(R.id.image); imageview1= (ImageView) findViewById(R.id.image_comp); Bitmap bitmap= BitmapFactory.decodeFile(path); showBitMap(bitmap); imageview.setImageBitmap(bitmap); //质量压缩 massCompression(bitmap,100,"aa_100.png"); //二级采样 doubleSampling();}@TargetApi(Build.VERSION_CODES.JELLY_BEAN)private void doubleSampling() { //Option二次采样压缩的配置参数 BitmapFactory.Options options=new BitmapFactory.Options(); //加载Bitmap时 只加载图片的信息 边框 不加载图片本身 options.inJustDecodeBounds = true; //把图片的信息 保存到options BitmapFactory.decodeFile(path,options); ViewGroup.LayoutParams lp = imageview1.getLayoutParams(); int imageWidth = lp.width; int imageHeight= lp.height; Log.e("bitmap", "onCreate: "+imageWidth+"---"+imageHeight); //300 200 int size=1; while(options.outWidth/size>imageWidth||options.outHeight/size>imageHeight){ size=size*2; } options.inSampleSize=size; options.inJustDecodeBounds=false; Bitmap bitmap = BitmapFactory.decodeFile(path,options); showBitMap(bitmap); massCompression(bitmap,30,"aa_30_1.png"); imageview1.setImageBitmap(bitmap);}private void massCompression(Bitmap bitmap,int quality,String fileName) { String savePath = "/sdcard/Download/"+fileName; try { FileOutputStream fos=new FileOutputStream(savePath); bitmap.compress(Bitmap.CompressFormat.JPEG,quality,fos); fos.flush(); fos.close(); } catch (Exception e) { e.printStackTrace(); }}private void showBitMap(Bitmap bitmap) { int width= bitmap.getWidth(); int height =bitmap.getHeight(); int byteCount = bitmap.getByteCount(); int byteCount1 = bitmap.getRowBytes()*bitmap.getHeight(); Log.e("bitmap", "onCreate: "+width+"---"+height+"---"+byteCount+"---"+byteCount1);}
}
阅读全文
0 0
- 质量压缩与二级采样
- 图片的压缩与二级采样
- 图片的压缩与二级采样
- 二次采样质量压缩
- 二次采样及质量压缩
- 采样与压缩感知
- Android 图片二次采样、质量压缩
- Android 图片二次采样、质量压缩
- Android 图片二次采样、质量压缩
- Android 图片二次采样、质量压缩
- 图片的质量压缩和二次采样
- 图片二次采样和按质量压缩
- Android 图片二次采样、质量压缩
- Android 图片二次采样、质量压缩
- Android---------二次采样和质量压缩
- 二级采样
- 详解Bitmap尺寸压缩与质量压缩
- 图片的二级采样
- harbor 高可用部署
- AE--属性表添加字段,修改字段属性
- 在看一个$injector用法的demo,下面是demo的所有代码:
- Spring框架的主要功能
- elasticsearch源码分析之启动过程
- 质量压缩与二级采样
- BZOJ 1211: [HNOI2004]树的计数 prufer编码
- 1004. Counting Leaves (30)
- 比特币开发专题(矿池挖矿PPS和PPLNS哪个挖矿收益高?)
- JavaScript知识点的总结
- centos64位中 fastDFS的安装以及nginx反向代理实现搭建图片服务器(二)
- c#中treeview的使用方法
- 如何在Word中排出漂亮的代码
- 你应该知道的 RPC 原理