0

この平和なコードを最適化する方法は? メソッドで約 1 分かかります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
  }
}

私はObrolSimpleHostCameraFragment から呼び出しています:

PictureTransaction xact = new PictureTransaction(getHost());
xact.needBitmap(true);
takePicture(xact);
4

1 に答える 1