S3(GT-I9300)相机preVIEW持有人的bug持有人、相机、GT、preVIEW

2023-09-05 03:38:15 作者:爱在夜里翻墙

我们创建了一个基于 android.hardware.Camera 类的自定义相机。 当我们preSS按钮拍照,预期的行为是拍照,看到了还在拍摄的照片上查看屏幕。但相机仍然工作/取景器则呈现出'活'射门(而不是还在审查),当我们去检查屏幕。 它看起来像座不工作。

We created a custom camera based on android.hardware.Camera class. When we press the button "take a photo", the expected behavior is to take the photo and see the still captured photo on a Review Screen. BUT , the camera still works / the viewfinder is showing a 'live' shot (instead of the still Review) when we get to the Review Screen. It looks like the holder doesn't work.

这已被观察到的一些三星Galaxy S3 手机( GT-I9300 );但奇怪的是在所有其它车型一切工作正常(静止图像出现在屏幕审​​查,因为它应该)。

This has been observed on some Samsung Galaxy S3 phones (GT-I9300); but strangely on all other models everything works fine (the still image appears in the Review Screen as it should).

推荐答案

我的解决方案到这一点是创建一个布局,其中一个观点占据了同样的观点作为surfaceview。

My solution up to this point is to create a layout where a view takes up the same view as the surfaceview.

然后我得到的视图范围为preVIEW(在我的情况下,它的屏幕尺寸)

Then I get the view bounds for the preview (in my case it's the size of the screen)

//Get our screen size
    Display display = ((WindowManager) getSystemService(Context.WINDOW_SERVICE))
            .getDefaultDisplay();
    DisplayMetrics metrics = getResources().getDisplayMetrics();
    Point size = new Point();
    try {
        display.getSize(size);
        w_width = size.x;
        w_height = size.y;
    } catch (NoSuchMethodError e) {
        w_width = display.getWidth();
        w_height = display.getHeight();
    }

然后,我设置回调为:

Then I set the callback to be:

callback = new Camera.PictureCallback() {
            @Override
            public void onPictureTaken(byte[] bytes, Camera camera) {
                //Get the view bounds to determine how to manipulate this image
                BitmapFactory.Options options = new BitmapFactory.Options();
                options.inJustDecodeBounds = true;
                BitmapFactory.decodeByteArray(bytes, 0, bytes.length, options);

                //If the image is smaller than the screen, don't make the image bigger
                int finalWidth = (w_width < options.outWidth) ? w_width : options.outWidth;
                int finalHeight = (w_height < options.outHeight) ? w_height : options.outHeight;
                int inSampleSize = 1;
                options = new BitmapFactory.Options();
                if (finalHeight > w_height || finalWidth > w_width) {

                    // Calculate ratios of height and width to requested height and width
                    final int heightRatio = Math.round((float) finalHeight / (float) w_height);
                    final int widthRatio = Math.round((float) finalWidth / (float) w_width);

                    // Choose the smallest ratio as inSampleSize value, this will guarantee
                    // a final image with both dimensions larger than or equal to the
                    // requested height and width.
                    inSampleSize = heightRatio < widthRatio ? heightRatio : widthRatio;
                }

                options.inSampleSize = inSampleSize;

                //Decode the smaller image
                Bitmap b = BitmapFactory.decodeByteArray(bytes, 0, bytes.length, options);

                //Rotate the image correctly
                Matrix mat = new Matrix();
                mat.postRotate(orientation);
                Bitmap newBitmap = Bitmap.createBitmap(b, 0, 0, options.outWidth, options.outHeight, mat, true);
                imagePreview.setBackgroundDrawable(new BitmapDrawable(newBitmap));
                imagePreview.setVisibility(View.VISIBLE);
            }
        };

所以基本上表面观从未停止显示preVIEW,但ImageView的隐藏它,使用户无法看到它。

So basically the surface view never stops showing the preview, but the imageview hides it so the user can't see it.

然后,如果用户决定不保留图像然后我就重新隐藏视图和surfaceView将继续展示现场preVIEW。幸运的是,GS3似乎并不介意有人在叫camera.start preVIEW();即使在preVIEW已经发生了。

Then if the user decides not to keep the image then I just re-hide the view and the surfaceView will keep showing the live preview. Luckily the GS3 does not seem to mind someone calling "camera.startPreview();" even when the preview is already happening.

我真的不喜欢这个答案,但它是所有我在的星系S3时运作的瞬间。它曾在老设备(2.3及以上),我已经尝试过,但它绝对只是一个解决方法。

I really don't like this answer but it's all I have at the moment that works on the galaxy S3. It has worked on older devices (2.3 and up) that I have tried but it is definitely just a work-around.