我正在编写一个代码将png文件转换回bmp并将其保存在SD卡上。这是我现在的代码。将位图保存到SD卡Android
FileInputStream in;
BufferedInputStream buf;
try {
in = new FileInputStream("File_Path_to_Read.png");
buf = new BufferedInputStream(in);
byte[] bMapArray= new byte[buf.available()];
buf.read(bMapArray);
Bitmap bMap = BitmapFactory.decodeByteArray(bMapArray, 0, bMapArray.length);
//Code segment to save on file
int numBytesByRow = bMap.getRowBytes() * bMap.getHeight();
ByteBuffer byteBuffer = ByteBuffer.allocate(numBytesByRow);
bMap.copyPixelsToBuffer(byteBuffer);
byte[] bytes = byteBuffer.array();
FileOutputStream fileOuputStream = new FileOutputStream("File_Path_To_Save.bmp");
fileOuputStream.write(bytes);
fileOuputStream.close();
if (in != null) {
in.close();
}
if (buf != null) {
buf.close();
}
} catch (Exception e) {
}
我在保存bMap到SD卡时遇到问题。我找到的所有例子都使用bMap.compress()。使用这种方法我不能保存为BMP。有人可以举例说明如何在Sdcard上保存位图吗?
编辑: 我现在可以将文件保存为.bmp到SD卡。但它不会达到原始大小。任何关于将PNG转换为BMP的建议?
'位.compress(Bitmap.CompressFormat.JPEG,80出)',只要您使用此方法,保存的图像质量的变化总是让你不得不改变2亲自试一试的最合适该方法的参数。 – CodeWarrior
我知道使用压缩方法时图像质量发生了变化。但是,我正在寻找一种方法将JPEG转换回BMP。原始的BMP就像使用我编辑的代码80 Mb,我得到14 KB。很显然,解压缩不工作...可以转换回BMP(从JPEG)在Android上完成? – user340