如何在Android中将位图转换为jpeg文件?

 我的 发布于 2023-02-13 14:00

我在这里有点失落.我必须将位图从裁剪图像转换为.jpeg文件.我已经查看了其他相关问题,但没有一个与我相关.(大多数都被恢复为文件到位图)

提前致谢

PS.第一次Android开发

1 个回答
  • 用这个:

    Bitmap bmp = null;
    ByteArrayOutputStream stream = new ByteArrayOutputStream();
    bmp.compress(Bitmap.CompressFormat.JPEG, 100, stream);
    byte[] byteArray = stream.toByteArray();
    

    为此你可以使用这个:

    FileInputStream fileInputStream = null;
    
    File file = new File("yourfile");
    
    byteArray = new byte[(int) file.length()];
    
    try {
        //convert file into array of bytes
        fileInputStream = new FileInputStream(file);
        fileInputStream.read(bFile);
        fileInputStream.close();
    
        //convert array of bytes into file
        FileOutputStream fileOuputStream =
                new FileOutputStream("C:\\testing2.txt");
        fileOuputStream.write(bFile);
        fileOuputStream.close();
    
        System.out.println("Done");
    } catch (Exception e) {
        e.printStackTrace();
    }
    

    而且有关更多信息,请点击此处

    2023-02-13 14:03 回答
撰写答案
今天,你开发时遇到什么问题呢?
立即提问
热门标签
PHP1.CN | 中国最专业的PHP中文社区 | PNG素材下载 | DevBox开发工具箱 | json解析格式化 |PHP资讯 | PHP教程 | 数据库技术 | 服务器技术 | 前端开发技术 | PHP框架 | 开发工具 | 在线工具
Copyright © 1998 - 2020 PHP1.CN. All Rights Reserved 京公网安备 11010802041100号 | 京ICP备19059560号-4 | PHP1.CN 第一PHP社区 版权所有