Comments (5)
@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.
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.
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.
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.
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)
- Camera front and back issue
- Kotlin 1.4 update breaks the library's critical functionality HOT 4
- With Kotlin's 1.4+ update the Fotoapparat's build() function crashes with error: HOT 3
- How to get bitmap image after takepicture ? HOT 1
- Crash On Vivo y20i on setPreviewCallback HOT 1
- I have implemented updateConfiguration but the screen is not refreshing.
- JCenter to be sunset on 2020-05-01 HOT 8
- How to change ratio to 1:1 in preview and photo result? and is it posibble to force UI preview camera scaletype fixXY?
- Is there possible disable audio and screen blink when calls methos takePicture()?
- Como se agrega fotoapparat, ahora que se ha quitado jcenter
- Not able to take picture
- Repeatedly calling fotoapparat.takePicture() causes app to crash
- The difference between preview and result obtained.
- CameraView not working HOT 1
- Is the Camera2 API used? HOT 1
- `takePicture()` freezes on API 33. HOT 6
- Android Studio Electric Eel problems. HOT 7
- DEX error after updating Gradle and Kotlin version HOT 1
- adding implementation 'io.fotoapparat:fotoapparat:2.7.0' doenst work HOT 2
- CameraView was not found in the project or the libraries
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from fotoapparat.