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

Distorted preview after adjusting for weird screen sizes #10

Closed
yjung0991 opened this issue Jan 16, 2019 · 12 comments
Closed

Distorted preview after adjusting for weird screen sizes #10

yjung0991 opened this issue Jan 16, 2019 · 12 comments
Assignees

Comments

@yjung0991
Copy link

yjung0991 commented Jan 16, 2019

Hey Mitch, thanks for the great tutorials.

I'm currently enrolled to your custom camera course and faced with some issues in branch 2.5.

First, here is my phone test (Samsung Galaxy S9):
phone_test

I'm getting a distorted preview like this one after adjusting for weird screen sizes according to your instruction and code from branch 2.5:
distorted_preview_after_branch25

The code from branch 2.4 did not show this distortion (but did have a bottom padding) so I compared the logcat results for branch 2.4 end and 2.5 end. Here are the results:
Branch 2.4
branch24end

Branch 2.5
branch25end

It seems the previewWidth and previewHeight shrink to 256:144 (!?) after adding some new codes from branch 2.5. The first one is the change you mention in your video, which is the configureTransform method in Camera2Fragment :
configuretransform

The second one was not explained in the video, but it is the setAspectRatio in your ScalingTextureView class.
setaspectratio

Do you think the previewWidth and previewHeight were affected here?
How should I make the aspect ratio correct and remove the bottom paddings in my app?
I want to know your thoughts. Thank you!

@mitchtabian
Copy link
Owner

mitchtabian commented Jan 16, 2019 via email

@mitchtabian
Copy link
Owner

mitchtabian commented Jan 16, 2019

I'm pretty sure it's your mPreviewSize variable. For some reason it's being set to that tiny size. Are you sure you copied my copy correctly? To test, write this write this just below the two log outputs that print the preview width and height at the bottom of the file.

mPreviewSize = new Size(1280, 720);
Log.d(TAG, "setUpCameraOutputs: preview width: " + mPreviewSize.getWidth());
Log.d(TAG, "setUpCameraOutputs: preview height: " + mPreviewSize.getHeight());

If that works then we know it's a problem with the mPreviewSize variable.

@yjung0991
Copy link
Author

Wow, writing that line did solve the issue. "mPreviewSize = new Size(1920, 1080)" worked as well.
it_works01

Would putting the line "mPreviewSize = new Size(1920, 1080);" at this location prevent future issues regarding resolution? Or is there some place else that should be fixed?
it_works02

@mitchtabian
Copy link
Owner

Print a log to see what size is selected from this part

if(largest != null){
    mPreviewSize = Utility.chooseOptimalSize(map.getOutputSizes(SurfaceTexture.class),
    rotatedPreviewWidth, rotatedPreviewHeight, maxPreviewWidth,
    maxPreviewHeight, largest);
    // print a log here
}

@yjung0991
Copy link
Author

The size selected here is 256:144. I also checked the screenshots of my log from branch 24 end and branch 25 end and it shows 1920:1080 shrinking to 256:144.. hm..

1901170041

@mitchtabian
Copy link
Owner

Then the "ChooseOptimalSize" method is flawed (I doubt that), or one of the inputs to that method are incorrect.
I'll take a look at that later.

@mitchtabian mitchtabian self-assigned this Jan 16, 2019
@yjung0991
Copy link
Author

Just checked to see if my Utility class is different from your code in branch 2.5, and it looks they are identical. Thanks for helping me out!

@mitchtabian
Copy link
Owner

This is very strange. I own an s8 and the screen is almost identical.
There isn't much I can do on my end to debug this unfortunately since I don't have an S9.
Replace the "largest != null" if statement with this and show me the log again please.

if(largest != null){
        Log.d(TAG, "setUpCameraOutputs: largest: " + largest.toString());
        mPreviewSize = Utility.chooseOptimalSize(map.getOutputSizes(SurfaceTexture.class),
        rotatedPreviewWidth, rotatedPreviewHeight, maxPreviewWidth,
        maxPreviewHeight, largest);
 }

@yjung0991
Copy link
Author

Hey Mitch, logcat says
largest: 3264x1836
Thanks for your help!

image

@mitchtabian
Copy link
Owner

I'm honestly really not sure. It's very strange.
Just to confirm, have you tried cloning the repository fresh, going to branch 2.5, and running it?
If you have, does it still give you the issue?

@yjung0991
Copy link
Author

Hi Mitch, I haven't tried to clone it because I am not familiar with github. But I will try it and check the logs again, get back to you. Thanks!

@mitchtabian
Copy link
Owner

I'm pretty sure I show you in this video: https://codingwithmitch.com/courses/android-custom-camera/how-use-source-code/

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

2 participants