我将JPG图像上传为byte [],但在转换为byte []之前将EXIF的位图剥离。如何上传原始jpg而不将其转换为位图?

File imagefile = new File(filepath + "DSC00021.jpg");
FileInputStream fis = new FileInputStream(imagefile);
Bitmap bi = BitmapFactory.decodeStream(fis); // EXIF info lost
ByteArrayOutputStream baos = new ByteArrayOutputStream();
bi.compress(Bitmap.CompressFormat.JPG, 100, baos);
byte[] data = baos.toByteArray();


ps。我不想使用任何第三方图书馆。 ExifInterface只能写入文件,而不能写入流/字节数组。

最佳答案

通过以下方式将文件转换为位图

Bitmap bi = BitmapFactory.decode(filepath + "DSC00021.jpg");


您也可以指定选项,请查看API documentation

或者,如果要将元数据从一个文件交换到另一个文件,sanselan可能是最佳选择。当您处理图像(例如调整大小)时,这将非常有用。

sample code将指导您正确的方向。

10-08 07:50
查看更多