android – onPictureTaken byte []在某些设备中体积小
作者:互联网
我正在使用Surfaceview创建自定义相机应用程序.在我的应用程序中我拍摄的图片,但它在注4中完美地工作,它在xiaomi移动中有问题,我不知道为什么会发生这种情况.
注4 onPictureTaken字节[]大小是原始的.
但
xiaomi onPictureTaken Byte []大小始终为160×120
这是我的代码
PictureCallback mPicture = new PictureCallback() {
@Override
public void onPictureTaken(byte[] data, Camera camera) {
final BitmapFactory.Options sizeOptions = new BitmapFactory.Options();
// sizeOptions.inJustDecodeBounds = false;
sizeOptions.inScaled = false;
// sizeOptions.inDither = false;
sizeOptions.inPreferredConfig = Bitmap.Config.ARGB_8888;
BitmapFactory.decodeByteArray(data, 0, data.length, sizeOptions);
Log.d("onPictureTaken", "Bitmap is " + sizeOptions.outWidth + "x"
+ sizeOptions.outHeight);
int angleToRotate = getRoatationAngle(currentCameraId);
Log.d("Tag", "Rotation angle: " + angleToRotate);
if (currentCameraId == Camera.CameraInfo.CAMERA_FACING_FRONT)
angleToRotate = angleToRotate + 180;
final String albumId = Util.ReadSharePrefrence(getActivity(), Constant.SHRED_PR.KEY_Current_AlbumID);
new SavePhotoTask(albumId, data, angleToRotate, isChecked, orientation).executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
camera.startPreview();
}
};
解决方法:
我发帖约3个小时,但没有人评论.
我弄清楚问题是什么.它取决于参数部分Reference
这是我的代码
private void initPreview(int width, int height) {
if (camera != null && previewHolder.getSurface() != null) {
try {
camera.setPreviewDisplay(previewHolder);
} catch (Throwable t) {
// Log.e("PreviewDemo-surfaceCallback","Exception in setPreviewDisplay()");
}
Camera.Parameters parameters = camera.getParameters();
Camera.Size size = getBestPreviewSize(width, height, parameters);
parameters.setJpegQuality(90);
if (size != null) {
Log.d("", "initPreview: width = "+size.width+ " height = "+size.height);
parameters.setPreviewSize(size.width, size.height);
parameters.setPictureSize(size.width, size.height);
camera.setParameters(parameters);
cameraConfigured = true;
}
}
}
标签:android-bitmap,android,android-camera 来源: https://codeday.me/bug/20191002/1845433.html