本文介绍了某些设备中的 onPictureTaken byte[] 小尺寸的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在使用 Surfaceview 创建自定义相机应用程序.在我的应用程序中,我捕获了图片,但它在 Note 4 中运行良好,在小米移动中存在问题,我不知道发生这种情况的原因.
I Creating custom camera app i am using Surfaceview. In my app i capture the picture but it work perfectly in Note 4 and it problematic in xiaomi mobile and i don't the reason why this happen.
注意 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();
}
};
推荐答案
我发布了大约 3 个小时的问题,但没有人发表评论.
I am post question for about 3 hours but no one even commenting.
我知道问题出在哪里了.它取决于参数部分参考
I figure out whats the problem. It is depending on parameter part 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;
}
}
}
这篇关于某些设备中的 onPictureTaken byte[] 小尺寸的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!