调整照片方向

TempBranch
Matthew 9 months ago
parent 9116ca8bc9
commit 4396e9c4e9

@ -16,6 +16,7 @@ import android.content.IntentFilter;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.graphics.ImageDecoder;
import android.graphics.Matrix;
import android.location.Location;
import android.location.LocationListener;
import android.location.LocationManager;
@ -401,6 +402,8 @@ public class MicroPhotoService extends Service {
final boolean result = intent.getBooleanExtra("result", false);
final String path = intent.getStringExtra("path");
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);
if (photoOrVideo) {
@ -426,6 +429,17 @@ public class MicroPhotoService extends Service {
} else {
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) {
}
mService.captureFinished(mService.mNativeHandle, photoOrVideo, result && bm != null, bm, videoId);

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

Loading…
Cancel
Save