Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fullscreen camera preview #53

Open
Vibinreji opened this issue Sep 3, 2018 · 3 comments
Open

Fullscreen camera preview #53

Vibinreji opened this issue Sep 3, 2018 · 3 comments

Comments

@Vibinreji
Copy link

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

@CrazyOrr
Copy link
Owner

CrazyOrr commented Sep 4, 2018

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.

@Vibinreji
Copy link
Author

can u provide sample code for that?

@levon93
Copy link

levon93 commented Oct 3, 2018

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

}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants