我在这里有点失落.我必须将位图从裁剪图像转换为.jpeg文件.我已经查看了其他相关问题,但没有一个与我相关. (大多数都被恢复为文件到位图)
提前致谢
PS.第一次Android开发
解决方法:
用这个:
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();
}
还有更多信息请与here一起使用