调整照片方向

nx2024TEMP
Matthew 9 months ago
parent c8bdbe3842
commit 93eb3d5c2c

@ -16,6 +16,7 @@ import android.content.IntentFilter;
import android.graphics.Bitmap; import android.graphics.Bitmap;
import android.graphics.BitmapFactory; import android.graphics.BitmapFactory;
import android.graphics.ImageDecoder; import android.graphics.ImageDecoder;
import android.graphics.Matrix;
import android.location.Location; import android.location.Location;
import android.location.LocationListener; import android.location.LocationListener;
import android.location.LocationManager; import android.location.LocationManager;
@ -401,6 +402,8 @@ public class MicroPhotoService extends Service {
final boolean result = intent.getBooleanExtra("result", false); final boolean result = intent.getBooleanExtra("result", false);
final String path = intent.getStringExtra("path"); final String path = intent.getStringExtra("path");
final long videoId = intent.getLongExtra("videoId", 0); final long videoId = intent.getLongExtra("videoId", 0);
final int orientation = intent.getIntExtra("orientation", 0);
final boolean frontCamera = intent.getBooleanExtra("frontCamera", false);
Log.i(TAG, "Recording received(" + Long.toString(videoId) + "):" + path); Log.i(TAG, "Recording received(" + Long.toString(videoId) + "):" + path);
if (photoOrVideo) { if (photoOrVideo) {
@ -426,6 +429,17 @@ public class MicroPhotoService extends Service {
} else { } else {
bm = BitmapFactory.decodeFile(path); bm = BitmapFactory.decodeFile(path);
} }
if (orientation != 0 || frontCamera) {
Matrix matrix = new Matrix();
if (orientation != 0) {
matrix.postRotate(orientation);
}
if (frontCamera) {
matrix.postScale(-1, 1);
}
bm = Bitmap.createBitmap(bm, 0, 0, bm.getWidth(), bm.getHeight(), matrix, true);
}
} catch (Exception ex) { } catch (Exception ex) {
} }
mService.captureFinished(mService.mNativeHandle, photoOrVideo, result && bm != null, bm, videoId); mService.captureFinished(mService.mNativeHandle, photoOrVideo, result && bm != null, bm, videoId);

@ -271,6 +271,8 @@ public class RawActivity extends AppCompatActivity {
private int mOrientation = -1; private int mOrientation = -1;
private boolean mFrontCamera = false;
/** /**
* A {@link CameraCaptureSession } for camera preview. * A {@link CameraCaptureSession } for camera preview.
*/ */
@ -660,6 +662,12 @@ public class RawActivity extends AppCompatActivity {
int width = intent.getIntExtra("width", MAX_PREVIEW_WIDTH); int width = intent.getIntExtra("width", MAX_PREVIEW_WIDTH);
int height = intent.getIntExtra("height", MAX_PREVIEW_HEIGHT); int height = intent.getIntExtra("height", MAX_PREVIEW_HEIGHT);
if (mOrientation == 90 || mOrientation == 270) {
int tmp = width;
width = height;
height = width;
}
mImageSize = new Size(width, height); mImageSize = new Size(width, height);
mPhotoId = intent.getLongExtra("videoId", 0); mPhotoId = intent.getLongExtra("videoId", 0);
@ -747,6 +755,8 @@ public class RawActivity extends AppCompatActivity {
return false; return false;
} }
mFrontCamera = characteristics.get(CameraCharacteristics.LENS_FACING) == CameraCharacteristics.LENS_FACING_FRONT;
StreamConfigurationMap map = characteristics.get( StreamConfigurationMap map = characteristics.get(
CameraCharacteristics.SCALER_STREAM_CONFIGURATION_MAP); CameraCharacteristics.SCALER_STREAM_CONFIGURATION_MAP);
@ -1805,6 +1815,9 @@ public class RawActivity extends AppCompatActivity {
// intent.setPackage(packageName); // intent.setPackage(packageName);
intent.putExtra("photoOrVideo", true); intent.putExtra("photoOrVideo", true);
intent.putExtra("result", result); intent.putExtra("result", result);
intent.putExtra("orientation", mOrientation);
intent.putExtra("frontCamera", mFrontCamera);
if (!TextUtils.isEmpty(path)) { if (!TextUtils.isEmpty(path)) {
intent.putExtra("path", path); intent.putExtra("path", path);
} }

Loading…
Cancel
Save