这是我目前将位图(2560x1440分辨率)保存到SD卡的代码:
private void saveImageToDiskTest()
{
long startTime = System.currentTimeMillis();
String fileName = "hid.png";
String completePath = Environment.getExternalStorageDirectory() + "/Pictures/" + fileName;
final Bitmap bitmap = BitmapFactory.decodeResource(getResources(), R.drawable.start_image_left);
FileOutputStream out = null;
try {
out = new FileOutputStream(completePath);
bitmap.compress(Bitmap.CompressFormat.PNG, 100, out);
} catch (Exception e) {
e.printStackTrace();
} finally {
try {
if (out != null) {
out.close();
}
} catch (IOException e) {
e.printStackTrace();
}
}
long stopTime = System.currentTimeMillis();
long elapsedTime = stopTime - startTime;
Toast.makeText(getApplicationContext(), String.valueOf(elapsedTime), Toast.LENGTH_LONG).show();
}
它有效,但速度很慢。保存图像需要10000毫秒。我该怎么做才能加快整个过程(不损失图像质量)?
我正在摩托罗拉Moto G gen2上测试它。