我的目标是
我遇到了第2步的问题。由于某些原因,此步骤会使图片包含锯齿状边缘并导致质量下降。如果我执行第1步并将字节直接保存到文件中(没有第2步),那么图像看起来好多了。
如何在不降低质量的情况下将字节转换为位图(步骤2)?
@Override
public void onPictureTaken(byte[] byteData, Camera camera) {
String filePath = "PATH_TO_IMAGE_FILE";
//Save bytes directly
{
File pictureFile = new File(filePath + ".fromBytes");
try {
FileOutputStream fos = new FileOutputStream(pictureFile);
fos.write(byteData);
fos.close();
} catch (Exception error) {
Log.d( "File not saved: " , error.getMessage());
}
}
//convert to bitmap -> convert to bytes -> then save
{
//I think this is where is loses quality ??
Bitmap decodedBitmap = BitmapFactory.decodeByteArray(byteData, 0, byteData.length);
//
ByteArrayOutputStream blob = new ByteArrayOutputStream();
decodedBitmap.compress(Bitmap.CompressFormat.PNG, 100, blob);
byte[] bitmapdata = blob.toByteArray();
File pictureFile = new File(filePath + ".fromBitmap");
try {
FileOutputStream fos = new FileOutputStream(pictureFile);
fos.write(bitmapdata);
fos.close();
} catch (Exception error) {
Log.d( "File not saved: " , error.getMessage());
}
}
}
由于