图片压缩
来源:互联网 发布:js关闭alert弹出框 编辑:程序博客网 时间:2024/04/29 22:31
BitmapFactory.Options options = new BitmapFactory.Options();
options.inJustDecodeBounds = true;
//获取这个图片的宽和高
Bitmap bitmap = BitmapFactory.decodeFile(filepath,options);
options.inJustDecodeBounds =false;
//计算缩放比
int be = (int)(options.outHeight / (float)65);
if(be <= 0)
be =1;
options.inSampleSize =be;
//重新读入图片
bitmap = BitmapFactory.decodeFile(filepath,options);
int w = bitmap.getWidth();
int h=bitmap.getHeight();
//保存入sdCard
File tp=new File(文件目录);
if(!tp.exists())
{
tp.mkdirs();
}
String newfile=文件地址;
File file2= new File(newfile);
try {
FileOutputStream out = new FileOutputStream(file2);
if(bitmap.compress(Bitmap.CompressFormat.PNG, 100, out)){
out.flush();
out.close();
}
} catch (Exception e) {
// TODO: handle exception
e.printStackTrace();
}
options.inJustDecodeBounds = true;
//获取这个图片的宽和高
Bitmap bitmap = BitmapFactory.decodeFile(filepath,options);
options.inJustDecodeBounds =false;
//计算缩放比
int be = (int)(options.outHeight / (float)65);
if(be <= 0)
be =1;
options.inSampleSize =be;
//重新读入图片
bitmap = BitmapFactory.decodeFile(filepath,options);
int w = bitmap.getWidth();
int h=bitmap.getHeight();
//保存入sdCard
File tp=new File(文件目录);
if(!tp.exists())
{
tp.mkdirs();
}
String newfile=文件地址;
File file2= new File(newfile);
try {
FileOutputStream out = new FileOutputStream(file2);
if(bitmap.compress(Bitmap.CompressFormat.PNG, 100, out)){
out.flush();
out.close();
}
} catch (Exception e) {
// TODO: handle exception
e.printStackTrace();
}
- 图片压缩。大小压缩
- 图片压缩按比例压缩
- 压缩图片
- 压缩图片
- 图片压缩
- 图片压缩
- 图片压缩
- 图片压缩
- 压缩图片
- 图片压缩
- 图片压缩
- 图片压缩
- 图片压缩
- 图片压缩
- 图片压缩
- 图片压缩
- 压缩图片
- 图片压缩
- ebs 组织
- STM32(Cortex-M3)中的中断优先级概念
- DMA
- C++多线程(一) windows.h
- win7_hadoop_java_eclipse version
- 图片压缩
- 基于STM32的CAN通信网-----一种ID配置方法
- EBS常用数据表
- C++ 输入输出流之标准I/O
- C 冒泡排序 练习
- MFC---消息机制
- 内存结构、堆结构及内存分配函数
- Shell脚本 字符串大小比较 字符串是否相等比较 字符串是否为空判断
- Android开发学习之SQLite数据库初探