Closed kkhalilov closed 11 months ago
to solve this problem you shold replace assetFromPath function node_modules/nativescript-camera-plus/helpers.js to:
`export function assetFromPath(path, width, height, keepAspectRatio) {
let scaledSizeImage = android.graphics.BitmapFactory.decodeFile(path);
const ei = new android.media.ExifInterface(path); // filename is the path to the native Android asset
const orientation = ei.getAttributeInt(android.media.ExifInterface.TAG_ORIENTATION, android.media.ExifInterface.ORIENTATION_NORMAL);
function rotateBitmap(source, angle, isShouldScale = false) {
const matrix = new android.graphics.Matrix();
matrix.postRotate(angle);
if (isShouldScale) matrix.preScale(1, -1)
return android.graphics.Bitmap.createBitmap(source, 0, 0, source.getWidth(), source.getHeight(), matrix, true);
}
switch (orientation) {
case android.media.ExifInterface.ORIENTATION_ROTATE_90:
scaledSizeImage = rotateBitmap(scaledSizeImage, 90);
break;
case android.media.ExifInterface.ORIENTATION_TRANSVERSE:
scaledSizeImage = rotateBitmap(scaledSizeImage, -90, true);
break;
case android.media.ExifInterface.ORIENTATION_ROTATE_180:
scaledSizeImage = rotateBitmap(scaledSizeImage, 180);
break;
case android.media.ExifInterface.ORIENTATION_ROTATE_270:
scaledSizeImage = rotateBitmap(scaledSizeImage, 270);
break;
}
const tempFilePath = Application.android.context.getExternalFilesDir(null).getAbsolutePath() + `/rotatedImage${Date.now()}.jpg`;
const outputStream = new java.io.FileOutputStream(tempFilePath);
scaledSizeImage.compress(android.graphics.Bitmap.CompressFormat.JPEG, 100, outputStream);
outputStream.close();
const asset = new ImageAsset(tempFilePath);
asset.options = {
width,
height,
keepAspectRatio,
};
return asset;
}`
"@nstudio/nativescript-camera-plus": "4.2.0", "@nativescript/android": "8.5.4", "@nativescript/core": "8.5.2", "nativescript": "8.5.3",
https://github.com/nstudio/nativescript-camera-plus/assets/144614606/f394e1be-bacd-4249-8fc0-2969287bea79