Giter Club home page Giter Club logo

Comments (5)

Diolor avatar Diolor commented on May 25, 2024 2

@andrewcking functionality has been add in 1.2.0.

You can now simply add this to your builder: .previewScaleType(ScaleType.CENTER_CROP) .

This would solve your needs. Let us know!

from fotoapparat.

Diolor avatar Diolor commented on May 25, 2024

If you want to display the full uncropped preview, then the preview size must have the same aspect ratio with the photo aspect ratio. That's right.

Personally I have not tried this myself to know the edge cases and cannot think of any right now. What have you encountered with this approach?

from fotoapparat.

dmitry-zaitsev avatar dmitry-zaitsev commented on May 25, 2024

Currently, the camera view is resized to make sure that the smallest side of the camera frame matches the smallest side of the view. That is to make sure that there won't be any blank lines on the screen.

We can add an option to fit camera preview inside of the view, but that would introduce blank lines mentioned above.

To be sure that we understand the problem correctly, could you please provide us some screenshots?

from fotoapparat.

andrewcking avatar andrewcking commented on May 25, 2024

So far my approach seems to be working on the devices I have tested it on (Galaxy s8, nexus 5, nexus 5x). I understand that showing the full sensor will result in gaps. Here is what my solution results in for the tall galaxy s8:

And the standard sized Nexus 5x:

As I said, there are probably far better way to do this but I basically call this method in my onCreate to get the aspect ratios for each camera (does Fotoapparat expose the dimensions it will be taking photos in when the cameras are created? That could simplify this).

public float getAspectRatios(Camera camera){
        Camera.Parameters params = camera.getParameters();
        List sizes = params.getSupportedPictureSizes();
        Camera.Size result = null;
        int biggestW = 0;
        int biggestH = 0;
        for (int i=0;i<sizes.size();i++){
            result = (Camera.Size) sizes.get(i);
            if (result.width >= biggestW && result.height >= biggestH) {
                biggestH = result.height;
                biggestW = result.width;
            }
        }
        camera.release();

        float aspect = (float)Math.max(biggestW,biggestH)/(float)Math.min(biggestW,biggestH);
        System.out.println("$$"+aspect);
        return aspect;
    }

And the calls in onCreate:

aspectRatioFront = getAspectRatios(Camera.open(CAMERA_FACING_FRONT));
aspectRatioBack = getAspectRatios(Camera.open(CAMERA_FACING_BACK));

Then whenever the camera is changed or initialized I just change the cameraView dimensions. I do this in case the aspect ratio that the front camera takes pictures in is different than the back camera (as is the case with my nexus 5 where the back camera is only near 4:3 and the front is perfect 4:3).

cameraView.getLayoutParams().height = (int)(size.x*aspectRatio)

Where size.x is the screen width and aspectRatio is either aspectRatioFront or aspectRatioBack from above.

This seems to be working for me, though it involves a couple workarounds.

from fotoapparat.

Diolor avatar Diolor commented on May 25, 2024

I believe the cleanest solution is to have a parameter in the builder to allow you choose if you want the preview to be cropped or be full size. Like:

Fotoapparat
    .with(context)  
    .into(cameraView)  
    .preview(cropped())  // of full()

from fotoapparat.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.