我使用Surfaceview创建自定义相机应用程序。在我的应用程序中,我捕获图片,但它在Note 4中完美运行,并且在xiaomi mobile中有问题,我不知道为什么会发生这种情况。
Note 4 onPictureTaken Byte []尺寸为原创。
但是
xiaomi onPictureTaken Byte []大小始终为160x120
这是我的代码
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();
}
};
答案 0 :(得分:1)
我发帖约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;
}
}
}