Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
844 views
in Technique[技术] by (71.8m points)

android - onPictureTaken byte[] small size in some device

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.

Note 4 onPictureTaken Byte[] size is original.

BUT

xiaomi onPictureTaken Byte[] size is always 160x120

Here is my code

     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();
        }
    };
See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

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

Here is my code

 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;
            }
        }
    }

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...