Android 将位图转换为jpeg格式

Android 将位图转换为jpeg格式,android,Android,我有一个在android中拍摄的位图。这张照片是位图。我必须毫无损失地将这个位图转换成JPEG格式。我试过下面的代码 val file = File(filePath) profileImageBitmap.compress(Bitmap.CompressFormat.JPEG,100,FileOutputStream(file)) 但是当我使用RoundedBitmapFactoryDrawable设置jpeg图像时,捕获的图像非常小。我想把位图转换成jpeg格式。有人能帮我吗?谢谢。我认为

我有一个在android中拍摄的位图。这张照片是位图。我必须毫无损失地将这个位图转换成JPEG格式。我试过下面的代码

val file = File(filePath)
profileImageBitmap.compress(Bitmap.CompressFormat.JPEG,100,FileOutputStream(file))

但是当我使用RoundedBitmapFactoryDrawable设置jpeg图像时,捕获的图像非常小。我想把位图转换成jpeg格式。有人能帮我吗?谢谢。

我认为这可能有用:

使用以下命令:

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();
    }
更多信息,请点击

请阅读更多解决方案

希望能有所帮助