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();
            }
        }
    }
}
最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容

  • 又识梅妹网络间 一声问候润心田 清风明月无俗念 淡淡牵挂醉流年 远隔千里一根弦 高山流水两人弹 天下虽大知音少 春...
    Zyh阳光总在风雨后阅读 453评论 1 0
  • 泡泡鱼丸大小姐阅读 128评论 0 0
  • 最近红楼君回老家办点事情,这篇文章是在刚刚完成母上大人吩咐的任务——拖地之后无聊之下写的,因为是突发奇想加...
    红楼先生阅读 4,039评论 0 3