BitmapUtil.java 文件源码

java
阅读 35 收藏 0 点赞 0 评论 0

项目:GCSApp 作者:
public static void saveBitmapFronPath(String srcPath, String picName, String filePath)
        throws FileNotFoundException {

    Options options = new Options();
    options.inJustDecodeBounds = true;
    Bitmap temp = BitmapFactory.decodeFile(srcPath, options);
    options.inJustDecodeBounds = false;
    int actualWidth = options.outWidth;
    int actualHeight = options.outHeight;
    int desiredWidth = actualWidth;
    int desiredHeight = actualHeight;
    if (actualWidth > NOMARL_SIZE && actualHeight > NOMARL_SIZE) {
        if (actualWidth > actualHeight) {
            desiredWidth = (int) (actualWidth * ((NOMARL_SIZE *1.0) / actualHeight));
            desiredHeight = NOMARL_SIZE;
        } else {
            desiredHeight = (int) (actualHeight * ((NOMARL_SIZE *1.0)/ actualWidth));
            desiredWidth = NOMARL_SIZE;
        }
    }
    options.inSampleSize = findBestSampleSize(actualWidth, actualHeight,
            desiredWidth, desiredHeight);
    options.inPurgeable = true;// 同时设置才会有效
    options.inInputShareable = true;//。当系统内存不够时候图片自动被回收

    temp = BitmapFactory.decodeFile(srcPath, options);
    Bitmap resizedBitmap = Bitmap.createScaledBitmap(temp, desiredWidth,
            desiredHeight, true);
    resizedBitmap = BitmapUtil.getRotationBitmap(srcPath, resizedBitmap);
    saveBitmap(resizedBitmap, new File(filePath,picName));
    if(null != temp){
        temp.recycle();
    }
    if(null != resizedBitmap){
        resizedBitmap.recycle();
    }
}
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号