revert unnecessary changes

pull/1184/head
Dmitry Naymushin 3 years ago
parent 93e3a57e19
commit 7ab66de0a6
  1. 2
      cameraview/src/main/java/com/otaliastudios/cameraview/BitmapCallback.java
  2. 26
      cameraview/src/main/java/com/otaliastudios/cameraview/PictureResult.java
  3. 7
      demo/src/main/kotlin/com/otaliastudios/cameraview/demo/PicturePreviewActivity.kt

@ -12,7 +12,7 @@ public interface BitmapCallback {
/**
* Notifies that the bitmap was successfully decoded.
* This is run on the UI thread.
* Returns a null object if an exception or an {@link OutOfMemoryError} was encountered.
* Returns a null object if an {@link OutOfMemoryError} was encountered.
*
* @param bitmap decoded bitmap, or null
*/

@ -3,11 +3,9 @@ package com.otaliastudios.cameraview;
import android.graphics.BitmapFactory;
import android.location.Location;
import android.os.Build;
import android.os.Handler;
import com.otaliastudios.cameraview.controls.Facing;
import com.otaliastudios.cameraview.controls.PictureFormat;
import com.otaliastudios.cameraview.internal.WorkerHandler;
import com.otaliastudios.cameraview.size.Size;
import java.io.File;
@ -109,11 +107,11 @@ public class PictureResult {
/**
* Returns the raw compressed, ready to be saved to file,
* in the given format or null if there was some error.
* in the given format.
*
* @return the compressed data stream or null
* @return the compressed data stream
*/
@Nullable
@NonNull
public byte[] getData() {
return data;
}
@ -138,19 +136,13 @@ public class PictureResult {
* @param callback a callback to be notified of image decoding
*/
public void toBitmap(int maxWidth, int maxHeight, @NonNull BitmapCallback callback) {
byte[] data = getData();
if (data == null) {
final Handler ui = new Handler();
WorkerHandler.execute(() -> ui.post(() -> callback.onBitmapReady(null)));
return;
}
if (format == PictureFormat.JPEG) {
CameraUtils.decodeBitmap(data, maxWidth, maxHeight, new BitmapFactory.Options(),
CameraUtils.decodeBitmap(getData(), maxWidth, maxHeight, new BitmapFactory.Options(),
rotation, callback);
} else if (format == PictureFormat.DNG && Build.VERSION.SDK_INT >= 24) {
// Apparently: BitmapFactory added DNG support in API 24.
// https://github.com/aosp-mirror/platform_frameworks_base/blob/nougat-mr1-release/core/jni/android/graphics/BitmapFactory.cpp
CameraUtils.decodeBitmap(data, maxWidth, maxHeight, new BitmapFactory.Options(),
CameraUtils.decodeBitmap(getData(), maxWidth, maxHeight, new BitmapFactory.Options(),
rotation, callback);
} else {
throw new UnsupportedOperationException("PictureResult.toBitmap() does not support "
@ -178,12 +170,6 @@ public class PictureResult {
* @param callback a callback
*/
public void toFile(@NonNull File file, @NonNull FileCallback callback) {
byte[] data = getData();
if (data != null) {
CameraUtils.writeToFile(data, file, callback);
} else {
final Handler ui = new Handler();
WorkerHandler.execute(() -> ui.post(() -> callback.onFileReady(null)));
}
CameraUtils.writeToFile(getData(), file, callback);
}
}

@ -27,13 +27,10 @@ class PicturePreviewActivity : AppCompatActivity() {
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_picture_preview)
if (pictureResult == null || (pictureResult?.data?.size ?: 0) <= 0) {
val result = pictureResult ?: run {
finish()
return
}
val result = requireNotNull(pictureResult)
val imageView = findViewById<ImageView>(R.id.image)
val captureResolution = findViewById<MessageView>(R.id.nativeCaptureResolution)
val captureLatency = findViewById<MessageView>(R.id.captureLatency)
@ -55,7 +52,7 @@ class PicturePreviewActivity : AppCompatActivity() {
// Log the real size for debugging reason.
val options = BitmapFactory.Options()
options.inJustDecodeBounds = true
BitmapFactory.decodeByteArray(result.data, 0, requireNotNull(result.data).size, options)
BitmapFactory.decodeByteArray(result.data, 0, result.data.size, options)
if (result.rotation % 180 != 0) {
Log.e("PicturePreview", "The picture full size is ${result.size.height}x${result.size.width}")
} else {

Loading…
Cancel
Save