Android剪裁图片
来源:互联网 发布:拱拱淘宝工具箱下载 编辑:程序博客网 时间:2024/06/04 18:20
ImageView iv_01 = (ImageView) findViewById(R.id.iv_01);ImageView iv_02 = (ImageView) findViewById(R.id.iv_02);ImageView iv_03= (ImageView) findViewById(R.id.iv_03);ImageView iv_04 = (ImageView) findViewById(R.id.iv_04);//第一种方法:压缩质量File saveFile = getFileStreamPath("compress.jpg");ByteArrayOutputStream baos = new ByteArrayOutputStream();Bitmap bitmap = BitmapFactory.decodeResource(getResources(), R.drawable.photo);bitmap.compress(Bitmap.CompressFormat.JPEG, 10, baos);try { FileOutputStream fos = new FileOutputStream(saveFile); fos.write(baos.toByteArray()); fos.flush(); fos.close();} catch (Exception e) { e.printStackTrace();}bitmap = BitmapFactory.decodeFile(saveFile.getAbsolutePath());iv_01.setImageBitmap(bitmap);//第二种方法:尺寸缩放int ratio = 4;bitmap = BitmapFactory.decodeResource(getResources(), R.drawable.photo);int width = bitmap.getWidth() / 4;int height = bitmap.getHeight() / 4;Rect rect = new Rect(0, 0, width, height);Bitmap bit = Bitmap.createBitmap(width, height, Bitmap.Config.ARGB_8888);Canvas canvas = new Canvas(bit);canvas.drawBitmap(bitmap, null, rect, null);iv_02.setImageBitmap(bit);//第三种方法:设置采样率BitmapFactory.Options options = new BitmapFactory.Options();options.inJustDecodeBounds = true;BitmapFactory.decodeResource(getResources(), R.drawable.photo, options);int w = options.outWidth;int h = options.outHeight;int standard = 100;int sample = w / 100;options.inJustDecodeBounds = false;options.inSampleSize = sample;bitmap = BitmapFactory.decodeResource(getResources(), R.drawable.photo, options);iv_03.setImageBitmap(bitmap);Log.e("TAG", w+"");Log.e("TAG", h+"");iv_04.setImageResource(R.drawable.photo);
本人水平有限,如有问题请及时与我联系
阅读全文
0 0
- android 图片剪裁
- Android 剪裁图片
- 图片剪裁 Android
- android 系统图片剪裁
- android 剪裁图片
- SimpleCropView Android图片剪裁
- android 自定义图片剪裁
- Android剪裁图片
- android编程之图片剪裁
- Android图片剪裁的实现
- Android图片的剪裁处理
- Android图片剪裁库:uCrop
- Android上传头像,图片剪裁,压缩图片
- Android上传头像,图片剪裁,压缩图片
- android拍照图片选取与图片剪裁
- Android上传头像,图片剪裁,压缩图片
- Android 按照比例剪裁图片,以及拍照并剪裁
- 图片剪裁
- nginx+lua 构建waf防火墙
- Spark中自定义排序
- 动态分配数组C++模板
- 公司做网站选择建站的几大原则
- 泛型集合List<T> 的详细用法
- Android剪裁图片
- 【笔记】ZooKeeper的安装与配置(单节点)
- MySQL的备份与恢复
- iOS跳转设置界面的多个url
- 处理大并发之一 对异步非阻塞的理解
- 线程安全和非安全用例
- linux安装php7+nginx
- java基础知识之接口
- Android TabLayout 在宽屏幕上tab不能平均分配的问题解决