android 根据图片路径和大小获取缩图
来源:互联网 发布:java.long.illegalargu 编辑:程序博客网 时间:2024/06/07 06:01
/**
* 获取缩图
*
* @param path
* @param width
* @param height
* @return
*/
public static Bitmap getBitmap(String path, int width, int heigth)
{
BitmapFactory.Options options = new BitmapFactory.Options();
options.inJustDecodeBounds = true;
try
{
BitmapFactory.decodeStream(new FileInputStream(new File(path)), null, options);
}
catch (FileNotFoundException e1)
{
e1.printStackTrace();
}
int width_tmp = options.outWidth;
int height_tmp = options.outHeight;
final int minSideLength = Math.min(width_tmp, height_tmp);
options.inSampleSize = computSize(options, minSideLength, width * heigth);
options.inJustDecodeBounds = false;
options.inInputShareable = true;
// 1
options.inPreferredConfig = Bitmap.Config.RGB_565;
options.inPurgeable = true;
try
{
// 2
Bitmap bm = BitmapFactory.decodeStream(new FileInputStream(new File(path)), null, options);
SoftReference<Bitmap> softBitmap = new SoftReference<Bitmap>(bm);
return softBitmap.get();
// return BitmapFactory.decodeFile(path, options);
}
catch (OutOfMemoryError e)
{
Log.e("ERROR", e.getMessage(), e);
}
catch (Exception e)
{
Log.e("ERROR", e.getMessage(), e);
}
return null;
}
* 获取缩图
*
* @param path
* @param width
* @param height
* @return
*/
public static Bitmap getBitmap(String path, int width, int heigth)
{
BitmapFactory.Options options = new BitmapFactory.Options();
options.inJustDecodeBounds = true;
try
{
BitmapFactory.decodeStream(new FileInputStream(new File(path)), null, options);
}
catch (FileNotFoundException e1)
{
e1.printStackTrace();
}
int width_tmp = options.outWidth;
int height_tmp = options.outHeight;
final int minSideLength = Math.min(width_tmp, height_tmp);
options.inSampleSize = computSize(options, minSideLength, width * heigth);
options.inJustDecodeBounds = false;
options.inInputShareable = true;
// 1
options.inPreferredConfig = Bitmap.Config.RGB_565;
options.inPurgeable = true;
try
{
// 2
Bitmap bm = BitmapFactory.decodeStream(new FileInputStream(new File(path)), null, options);
SoftReference<Bitmap> softBitmap = new SoftReference<Bitmap>(bm);
return softBitmap.get();
// return BitmapFactory.decodeFile(path, options);
}
catch (OutOfMemoryError e)
{
Log.e("ERROR", e.getMessage(), e);
}
catch (Exception e)
{
Log.e("ERROR", e.getMessage(), e);
}
return null;
}
- android 根据图片路径和大小获取缩图
- Android根据图片路径获取图片名字
- 根据图片路径来获取图片的真实大小
- 根据指定的图像路径和大小来获取缩略图
- Android手机读取相册图片,根据URI获取图片路径
- Android 获取图库图片 根据uri获取路径
- Android根据文件路径获取图片的名字
- Android之根据图片的Uri获取对应的路径
- android获取在线视频略缩图
- 根据路径获取图片,缩放图片
- Android相册中获取图片和路径
- Android相册中获取图片和路径
- android 根据uri获取路径
- Android 根据路径获取文件名
- android 通过uri获取图片并根据限制大小读取图片的方法
- Android获取图片路径
- 根据路径获取视频、图片的缩略图
- Android中如何根据图片url路径来获取网络图片
- VC中unicode环境下CString转char*的方法
- 装饰者模式--Decorator
- mysql count group by having
- 如何修改对话框的背景色
- 面向对象给了我们什么好处
- android 根据图片路径和大小获取缩图
- 如何在list中查找
- 线段树
- 银行管理系统
- 现在的黑客太可恶了为了流量攻击我的网站
- ERP系统容灾方案对ERP生产系统的影响
- Java中实现复制文件或文件夹
- Linux下tar.xz结尾的文件的解压方法
- Linux网络编程基础