Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,12 @@
## 0.6.3
Make quality of pictures in android better

## 0.6.2
Fix minor android bug that camera was crashing

## 0.6.1
Fix bug that was making builds on iOS fields

## 0.6.0
Add flash, auto exposure, zoom and auto focus support for IOS and Android

Expand Down
25 changes: 23 additions & 2 deletions android/src/main/java/io/flutter/plugins/camera/Camera.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package io.flutter.plugins.camera;

import static android.view.OrientationEventListener.ORIENTATION_UNKNOWN;
import static io.flutter.plugins.camera.CameraUtils.computeBestCaptureSize;
import static io.flutter.plugins.camera.CameraUtils.computeBestPreviewSize;

import android.annotation.SuppressLint;
Expand Down Expand Up @@ -176,8 +177,14 @@ public void onOrientationChanged(int i) {

recordingProfile =
CameraUtils.getBestAvailableCamcorderProfileForResolutionPreset(cameraName, preset);
captureSize = new Size(recordingProfile.videoFrameWidth, recordingProfile.videoFrameHeight);
previewSize = computeBestPreviewSize(cameraName, preset);


StreamConfigurationMap map = mCameraCharacteristics.get(
CameraCharacteristics.SCALER_STREAM_CONFIGURATION_MAP);
//TODO get the image best not the video
Size size = computeBestCaptureSize(map);
captureSize = size; // new Size(recordingProfile.videoFrameWidth, recordingProfile.videoFrameHeight);
previewSize = size; // computeBestPreviewSize(cameraName, preset);
}

private void setBestAERange(CameraCharacteristics characteristics) {
Expand Down Expand Up @@ -232,6 +239,7 @@ private void preparePictureImageReader() {
if (pictureImageReader != null) {
pictureImageReader.close();
}
//TODO make sure this is the biggest image
pictureImageReader =
ImageReader.newInstance(
captureSize.getWidth(), captureSize.getHeight(), ImageFormat.JPEG, 2);
Expand Down Expand Up @@ -533,6 +541,9 @@ public void captureStillPicture(String filePath, @NonNull final Result result) {
cameraDevice.createCaptureRequest(CameraDevice.TEMPLATE_STILL_CAPTURE);
captureBuilder.addTarget(pictureImageReader.getSurface());

//try increasing the quality of the image
captureBuilder.set(CaptureRequest.JPEG_QUALITY, (byte)90);

captureBuilder.set(CaptureRequest.CONTROL_AF_MODE,
mPreviewRequestBuilder.get(CaptureRequest.CONTROL_AF_MODE));

Expand Down Expand Up @@ -566,6 +577,9 @@ public void captureStillPicture(String filePath, @NonNull final Result result) {
captureBuilder.set(CaptureRequest.JPEG_ORIENTATION, getMediaOrientation());


//TODOD should this be here
captureBuilder.set(CaptureRequest.SCALER_CROP_REGION, mPreviewRequestBuilder.get(CaptureRequest.SCALER_CROP_REGION));

mCaptureSession.capture(
captureBuilder.build(),
new CameraCaptureSession.CaptureCallback() {
Expand Down Expand Up @@ -652,6 +666,11 @@ public void onConfigured(@NonNull CameraCaptureSession session) {
}
mPreviewRequestBuilder.set(
CaptureRequest.CONTROL_MODE, CameraMetadata.CONTROL_MODE_AUTO);

//TODO set the request quality
mPreviewRequestBuilder.set(
CaptureRequest.CONTROL_MODE, CameraMetadata.CONTROL_MODE_AUTO);

mCaptureSession.setRepeatingRequest(mPreviewRequestBuilder.build(), mCaptureCallback, null);


Expand Down Expand Up @@ -890,6 +909,8 @@ public void resumeVideoRecording(@NonNull final Result result) {
}

public void startPreview() throws CameraAccessException {
if (pictureImageReader == null || pictureImageReader.getSurface() == null) return;

createCaptureSession(CameraDevice.TEMPLATE_PREVIEW, pictureImageReader.getSurface());
}

Expand Down
13 changes: 11 additions & 2 deletions android/src/main/java/io/flutter/plugins/camera/CameraUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,9 @@
import android.hardware.camera2.CameraMetadata;
import android.hardware.camera2.params.StreamConfigurationMap;
import android.media.CamcorderProfile;
import android.util.Log;
import android.util.Size;
import io.flutter.plugins.camera.Camera.ResolutionPreset;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
Expand All @@ -19,6 +20,8 @@
import java.util.List;
import java.util.Map;

import io.flutter.plugins.camera.Camera.ResolutionPreset;

/** Provides various utilities for camera. */
public final class CameraUtils {

Expand All @@ -36,11 +39,17 @@ static Size computeBestPreviewSize(String cameraName, ResolutionPreset preset) {

static Size computeBestCaptureSize(StreamConfigurationMap streamConfigurationMap) {
// For still image captures, we use the largest available size.

Size[] outputSizes = streamConfigurationMap.getOutputSizes(ImageFormat.JPEG);

//TODO think about aspect ratios
return Collections.max(
Arrays.asList(streamConfigurationMap.getOutputSizes(ImageFormat.JPEG)),
Arrays.asList(outputSizes),
new CompareSizesByArea());
}



public static List<Map<String, Object>> getAvailableCameras(Activity activity)
throws CameraAccessException {
CameraManager cameraManager = (CameraManager) activity.getSystemService(Context.CAMERA_SERVICE);
Expand Down