Android 如何对本地图片进行缩略并重新命名

  /**
 * 传递一个创建小图的路径
 */
public static void _CreateSmallByLocalPath(String str) {
    int last = str.lastIndexOf(".");
    String path = str.substring(0, last);
    StringBuffer sb = new StringBuffer(path);
    sb.append("_s.png");
    Bitmap bitmap = BitmapFactory.decodeFile(str);
    Bitmap bitmap1 = ThumbnailUtils.extractThumbnail(bitmap, 608, 342);
    ByteArrayOutputStream baos = new ByteArrayOutputStream();
    bitmap1.compress(Bitmap.CompressFormat.PNG, 100, baos);
    BufferedOutputStream stream = null;
    try {
        //得到缩略图
        File file = new File(sb.toString());
        FileOutputStream fstream = new FileOutputStream(file);
        stream = new BufferedOutputStream(fstream);
        stream.write(baos.toByteArray());
    } catch (Exception e) {
        e.printStackTrace();
    } finally {
        if (stream != null) {
            try {
                stream.close();
            } catch (IOException e1) {
                e1.printStackTrace();
            }
        }
    }
}

你可能感兴趣的:(Android 如何对本地图片进行缩略并重新命名)