我要遍历Android上的照片,裁剪脸部,并仅用脸部保存JPEG。此过程需要一段时间,主要是因为insertImage函数每张照片最多需要一秒钟:
Bitmap newBitnmap;
try{
newBitnmap = Bitmap.createBitmap(myBitmap, a, b, c, d);
}catch(Exception e1){
Log.d(TAG, "doInBackground: error: " + e1);
return "error";
}
Log.d(TAG, "doInBackground: after new bitmap");
try {
Log.d(TAG, "detectAndCrop: 1");
fOutputStream = new FileOutputStream(newImageFile);
Log.d(TAG, "detectAndCrop: 2");
newBitnmap.compress(Bitmap.CompressFormat.JPEG, 60, fOutputStream);
Log.d(TAG, "detectAndCrop: 3");
fOutputStream.flush();
Log.d(TAG, "doInBackground: 3.1");
fOutputStream.close();
Log.d(TAG, "doInBackground: 3.2");
MediaStore.Images.Media.insertImage(mContext.getContentResolver(), newImageFile.getAbsolutePath(), newImageFile.getName(), newImageFile.getName());
Log.d(TAG, "detectAndCrop: 4");
} catch (FileNotFoundException e1) {
e1.printStackTrace();
} catch (IOException e3) {
e3.printStackTrace();
}
我只是想知道这是否是将jpeg保存到Android中的磁盘的正常时间,或者我做错了什么?