mitchtabian / TabianCustomCamera

Custom camera for android using camera2 api (DEPRECATED)
153 stars 64 forks source link

Distorted preview just sometimes #16

Closed sralmu closed 5 years ago

sralmu commented 5 years ago

Hey Mitch! First of all, thanks for the course and all the code you've done, it's helping me a lot with an university project.

I'm having some problems to get a well proportioned preview before capturing the image.

Here's my phone test (Huawei P8 Lite, ALE-L21): phoneinfo

Well, the thing is, when I first install the app and open it, the preview is well proportioned as you can see in this screenshot: okpreview

This is the LogCat the first time I open the app: firstinstalled

However, if I close the app and open it again, the preview is distorted: distortedpreview

But the LogCat seems exactly the same: closedandopened

And the most strange thing is, if now I exit the app (but leaving it in the background, not closing it definitely) and enter again, the preview is OK! And the LogCat I obtain is this: backgroundandopened

Also, this distortion has nothing to do with the captured image, which is always well proportioned despite the preview is OK or not. This is how the image looks like: capturedimage

I really don't know where the problem is, but obviously it has something to do with whether I close the app or leave it at the background (although the fact that it works well when I first install it is driving me crazy). In both cases, I think the program takes the same resolutions because of the log messages I obtain, so I don't know which is the difference.

Thanks in advance, it is very important for me to solve it.

mitchtabian commented 5 years ago

You see this https://github.com/mitchtabian/TabianCustomCamera/issues/13?

sralmu commented 5 years ago

Yes, but here https://github.com/mitchtabian/TabianCustomCamera/issues/13 the problem you solved was related to the onTouch method, which I haven't include in my code yet, and the distortion issue wasn't solved, I think.

However, I've just tested the last branch of your code (just in case I copied something wrong), and the problem persists.

Finally, I've found that the problem is not the code itself. The problem is related to Android Camera2 API for some reason.

This is what I've found: https://stackoverflow.com/questions/43319318/android-camera2-api-preview-sometimes-distorted

Modifying the openCamera method in order to delay the camera opening fixes the issue.

mitchtabian commented 5 years ago

Thanks for sharing your findings