S3 (GT-I9300) Camera Preview Error

We created a custom camera based on the android.hardware.Camera class. When we click the “take a picture” button, the expected behavior is to take a picture and see the photo taken on the review screen. BUT, the camera is still working / the viewfinder shows a “live” picture (and not still the view) when we get to the review screen. It seems that the holder is not working.

This is observed on some Samsung Galaxy S3 phones ( GT-I9300 ); but strange on all other models everything works fine (the image still appears on the review screen).

+6
source share
1 answer

My decision up to this point is to create a layout where the view takes the same form as the surface view.

Then I get estimates for the preview (in my case, this is the screen size)

 //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:

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

Thus, basically the surface view never stops showing the preview, but the image hides it so that the user cannot see it.

Then, if the user decides not to save the image, I just hide the view again and the View surface will continue to show a live preview. Fortunately, GS3 does not seem to mind that it calls "camera.startPreview ()"; even when the preview is already taking place.

I really don't like this answer, but everything that I have at the moment works in galaxy S3. He worked on older devices (2.3 and above) that I tried, but this is definitely just a workaround.

+3
source

All Articles