Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

小米mix2手机上,拍照出来的结果与预期不相符 #9

Closed
matbird opened this issue Sep 22, 2018 · 7 comments
Closed

小米mix2手机上,拍照出来的结果与预期不相符 #9

matbird opened this issue Sep 22, 2018 · 7 comments

Comments

@matbird
Copy link

matbird commented Sep 22, 2018

拍出来的照片跟预期的向左旋转了90度,
在华为麦芒的手机上测试是正常的

@matbird
Copy link
Author

matbird commented Sep 22, 2018

mCameraView.addCallback(new CameraView.Callback() {
@OverRide
public void onPictureTaken(CameraView cameraView, byte[] data) {
super.onPictureTaken(cameraView, data);
// 发现这个地方的data出来就已经旋转了
image2.setImageBitmap(BitmapFactory.decodeByteArray(data, 0, data.length));
mCameraView.cropImage(data, new SmartCameraView.CropCallback() {
@OverRide
public void onCropped(Bitmap bitmap) {
if(bitmap != null){
// testImageView.setImageBitmap(bitmap);
mPreview.setImageBitmap(bitmap);
String saveString = Utils.saveBitmap(bitmap);
showTip(saveString);
mCameraView.stopScan();
}
}
});
}
});

@matbird
Copy link
Author

matbird commented Sep 22, 2018

google/cameraview#22

@pqpo
Copy link
Owner

pqpo commented Sep 27, 2018

下个版本我更新一下,如果你解决了也可以给我提个 merge。

@pqpo
Copy link
Owner

pqpo commented Sep 27, 2018

#8

@jinke1984
Copy link

在三星的手机里面也发现了这种情况,我修改了下cropImage这个方法就可以了
public void cropImage(final byte[] data, final CropCallback cropCallback) {
new Thread() {
@OverRide
public void run() {
super.run();
int degress = 0;
Rect revisedMaskRect = getAdjustPictureMaskRect();
try{
final ExifInterface exifInterface = new ExifInterface(FormatTools.getInstance().Byte2InputStream(data));
final int attributeInt = exifInterface.getAttributeInt(ExifInterface.TAG_ORIENTATION,
ExifInterface.ORIENTATION_UNDEFINED);
switch (attributeInt) {
case ExifInterface.ORIENTATION_ROTATE_90:
Log.e("jinke","90");
degress = 90;
break;
case ExifInterface.ORIENTATION_ROTATE_180:
Log.e("jinke","180");
degress = 180;
break;
case ExifInterface.ORIENTATION_ROTATE_270:
Log.e("jinke","270");
degress = 270;
break;
default:
break;
}
}catch (IOException e){
e.printStackTrace();
}
final Matrix matrix = new Matrix();
matrix.setRotate(degress);
Bitmap tempBit = BitmapFactory.decodeByteArray(data, 0, data.length);
Bitmap bitmapSrc = Bitmap.createBitmap(tempBit, 0, 0, tempBit.getWidth(), tempBit.getHeight(), matrix, true);
if (revisedMaskRect != null) {
final Bitmap bitmap = Bitmap.createBitmap(bitmapSrc, revisedMaskRect.left,
revisedMaskRect.top, revisedMaskRect.width(), revisedMaskRect.height());
bitmapSrc.recycle();
tempBit.recycle();
post(new Runnable() {
@OverRide
public void run() {
cropCallback.onCropped(bitmap);
}
});
return;
}
post(new Runnable() {
@OverRide
public void run() {
cropCallback.onCropped(null);
}
});
}
}.start();
}

@pqpo
Copy link
Owner

pqpo commented Sep 29, 2018

使用的是 com.android.support:exifinterface ?

@pqpo
Copy link
Owner

pqpo commented Sep 29, 2018

v1.3.0 版本已解决

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants