如何优化这种和平的代码?方法大约需要一分钟saveImage
。
class ObrolSimpleHost extends SimpleCameraHost {
private final String[] SCAN_TYPES = {"image/webp"};
private Context context = null;
public ObrolSimpleHost(Context _ctxt) {
super(_ctxt);
this.context = getActivity();
}
@Override public void saveImage(PictureTransaction xact, Bitmap bitmap) {
File photo = getPhotoPath();
if (photo.exists()) {
photo.delete();
}
try {
FileOutputStream fos = new FileOutputStream(photo.getPath());
bitmap.compress(Bitmap.CompressFormat.WEBP, 70, fos);
fos.flush();
fos.getFD().sync();
if (scanSavedImage()) {
MediaScannerConnection.scanFile(context, new String[]{photo.getPath()}, SCAN_TYPES, null);
}
} catch (java.io.IOException e) {
handleException(e);
}
}
@Override public void saveImage(PictureTransaction xact, byte[] image) {
// do nothing
}
}
我ObrolSimpleHost
从 CameraFragment 打来电话:
PictureTransaction xact = new PictureTransaction(getHost());
xact.needBitmap(true);
takePicture(xact);