/**
* 获取缩图
*
* @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;
}