如何将位图转换为Android的JPEG文件? [英] How to convert a bitmap to a jpeg file in Android?

查看:147
本文介绍了如何将位图转换为Android的JPEG文件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在这里失去了一点点。我有一个位图从裁剪的图像转换为JPEG格式文件。我看过其他相关的问题,但他们都不相对于我的。 (大部分被恢复的文件,以位图)

I'm a little bit lost here. I have to convert a bitmap from a cropped image to an .jpeg file. I have looked to other related questions but none of them were relative to mine. (most were reverted as file to bitmap)

在此先感谢

PS。第一次Android开发

ps. first time Android development

推荐答案

使用这样的:

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

对于您可以使用此:

for that you can use this:

    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();
    }

,也为更多的信息去与这里

这篇关于如何将位图转换为Android的JPEG文件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆