FFmpegRecorder icon indicating copy to clipboard operation
FFmpegRecorder copied to clipboard

Fullscreen camera preview

Open Vibinreji opened this issue 7 years ago • 3 comments

I want make preview based on device width and height.look like its not working can anyone help me to do that

Vibinreji avatar Sep 03 '18 05:09 Vibinreji

You can make the preview TextureView fullscreen as long as you can find a supported preview size of the camera which has matching width-height ratio, otherwise the preview will be distorted.

CrazyOrr avatar Sep 04 '18 02:09 CrazyOrr

can u provide sample code for that?

Vibinreji avatar Sep 04 '18 06:09 Vibinreji

You don't need PREFERRED_PREVIEW_WIDTH and PREFERRED_PREVIEW_HEIGHT variables

add below code in onCreate() and use mPreviewWidth and mPreviewHeight where above variables needed.

DisplayMetrics displayMetrics = getResources().getDisplayMetrics();

        //assigning reverse values, because preview sizes are landscape by default
        //noinspection SuspiciousNameCombination
        mPreviewWidth = displayMetrics.heightPixels;
        //noinspection SuspiciousNameCombination
        mPreviewHeight = displayMetrics.widthPixels;

And also chnage TextureView

public class FullScreenTextureView extends TextureView {

    public FullScreenTextureView(Context context) {
        super(context);
    }

    public FullScreenTextureView(Context context, AttributeSet attrs) {
        super(context, attrs);
    }

    public FullScreenTextureView(Context context, AttributeSet attrs, int defStyleAttr) {
        super(context, attrs, defStyleAttr);
    }

    @Override
    protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
        super.onMeasure(widthMeasureSpec, heightMeasureSpec);
        int measuredWidth = getMeasuredWidth();
        int measuredHeight = getMeasuredHeight();
        int width = MeasureSpec.getSize(widthMeasureSpec);
        int height = MeasureSpec.getSize(heightMeasureSpec);
        if (0 == measuredWidth || 0 == measuredHeight) {
            setMeasuredDimension(width, height);
        } else {
            if (width < height * measuredWidth / measuredHeight) {
                setMeasuredDimension(height * measuredWidth / measuredHeight, height);
            } else {
                setMeasuredDimension(width, width * measuredHeight / measuredWidth);
            }
        }
    }

}

levon93 avatar Oct 03 '18 15:10 levon93