Android Camera Preview not Full Screen - android

I am developing a camera app but the camera is not full screen. I am using common "CameraPreview" class to open camera. it includes Surfaceview and Determining Optimal Size for camera. In tablet and phones, camera is not full screen. For example, tablet size is 1280x728 but camera size is 1024x768. It is shown in FrameLayout for which layout widht and height is FillParent. I could not understand and solve this issue. I wanna open camera in full screen without stretching.
Is there anybody got this issue and fix it?

Judging by the code here:(which you can use actually), you can use the method getSupportedPreviewSizes() and see what are the supported resolutions, 1024x768 could easily be the highest one available for this preview and as you found out, it is really the highest supported.
So those are the supported resolutions, there's no way you can get higher than the supported. You must find a workaround for this, like to put the preview in the center and surrond it with black frame or something like that.

Related

Camera2 API preview aspect is broken

I am using the Camera2 API to setup an imagecapture fragment. I only want to use the camera in portrait mode. So i have set this line in the manifest in the fragment's parent activity:
android:screenOrientation="portrait"
Which locks the camera preview to portrait. However, the image aspect is just wrong. When the image is captured, there is no issues with the aspect, and the image looks as it should, but is still not in full screen. I suspect the camera output is stretched to fill the screen in my preview. How do i make both the preview and the captured image fill the entire screen and keep its aspect ratio like Snapchat does it?
I have been using the Google sample as my reference, and changed the AutoFitTextureView to match_parent in the XML layout file.
this is how it looks in normal portrait
and this is how it looks when i rotate the phone and is still in portrait mode
AutoFillTextureView attempts to keep the aspect ratio correct, but if you're changing its layout parameters, it may not be able to.
Do things work correctly if you don't make it 'match_parent'?
In general, Android UI elements will fill themselves with the input data, so you need to set the View's size to the right aspect ratio to avoid stretching.
For anyone who has been facing this issue like I was and if you have been using the google sample from before Jun 2017, then tweaking a line in your AutoFitTextureView should fix the preview's aspect ratio. It's as simple as changing "<" to ">" which you can see here.

Small frontal camera preview (not fullscreen)?

is there a way to have a small camera preview inside a view? Not the classic fullscreen preview, I mean.
My idea is to create an app that allows the user to take pics of himself with the frontal camera, when it's dark.
Basically, I thought to put a small preview of the camera on the corner of the screen and setting the remaining part to full brightness (to use it like a "self flash").
Well, I don't have problems actually to set a view to a full brightness value, but I don't have any idea how to resize the frontal camera preview.
I hope you understood my intention...
Any help would appreciated!
I don't believe this idea will hold water, because the brightness of the screen may not be enough. But the technical question you ask is not very hard: you can put the ViewSurface for your preview in the main activity's xml with any size you choose (you can use the usual WISIWYG layout editor in ADS or AndroidStudio).

Image Sized a little-bit to small, and ratio changes on rotation

using the cwac-camera library,
on the left and on the right (more times just on the left), the final image and the preview gets cut after taking a picture.
Also Xperia Z1 -> FFC (Front Facing Camera) ->
left and right side images are cut
http://s7.directupload.net/images/140228/ei5saica.png
http://s14.directupload.net/images/140228/ftnecxau.png
Another issue:
Also I added the library's view into a fullscreen fragment which will not be recreated *on rotation* -> result -> somehow the screen-preview-ratio changes on
- portrait
- landscape
- and taking picture
Means: On portrait the head is a littlebit wider (more width) than on landscape, and after taking picture the preview image is also a little bit more stretched then the (live) preview berfore. But finally the image seems to be the correct one.
This Problem was seen on an HTC One :/
Note that StackOverflow is for programming questions. Nothing here is a question. If you feel that you have identified bugs, post an issue with complete steps to reproduce the problem, including device model(s) and Android OS version(s). Use StackOverflow for questions about the library.
using the cwac-camera library, on the left and on the right (more times just on the left), the final image and the preview gets cut after taking a picture.
I would guess that it is a variation on this issue.
Another issue
Part of this is presumably the same issue. With respect to "the screen-preview-ratio changes on portrait/landscape", if you are not creating a new CameraView, and you have the camera locked to landscape, then I do not see where I would be changing the preview behavior on an orientation change.
You may set preview size and picture size independently. But to achieve the best results, choose picture size that has same aspect ratio as your preview frame. E.g. for preview 640x480, you can use 3264x2448 picture. But if you use 1280x720 preview, you will be better served by a wide picture, e.g. 4128X2322.
Note that usually, the wide (16:9) format is achieved by essentially cropping a 4:3 picture.

Preview size wtith CWAC-Camera

I've been fighting for a while with https://github.com/commonsguy/cwac-camera
Managed to create my custom CameraFragment and a custom custom CameraHost.
I've overrode getPictureSize and getPreviewSize. With those two methods I'm able to find out which Sizes are able to be used. My overall idea is to capture a square image, and also preview it before capturing.
I've been testing and no device is returning a square-formatted Size, so I guess the best approach would be taking the Size nearest to my needs. Like if I need an 800x800 squared image, I will return the nearest Size, that would be (for example) 1280x1024
So far so good. The issue is the following:
Documentation states:
Usually, your CameraHost will be called with getPreviewSize()
Damn; my Nexus5 device never triggers this method, but a Genymotion emulator does. So in my emulator I can create a custom preview size, which I can't with my real device.
So I need some help with this issue. Why is it just "usually"? What can I do to change it to "always"?
On a second term, I need some tips: If I want an squared preview size, which I know it won't be available by default Sizes returned by getSupportedPreviewSizes, what can I do to display an square? Maybe overlaying a square on top of CameraFragment? Is it even possible? Or should I go for any other approach?
Anyways, congratulations on the library; it's absolutely clear and with so many options. No need to worry about "some devices". That's great as an Android Developer.
Thank you.
Why is it just "usually"? What can I do to change it to "always"?
Quoting the documentation:
If getRecordingHint() returns ANY or VIDEO_ONLY, though, CameraHost supplies the preview size via getPreferredPreviewSizeForVideo() instead of getPreviewSize(). If you wish to use a different preview size for video, return it, otherwise return null and we will use the results from getPreviewSize() instead.
On API Level 11+, the implementation of SimpleCameraHost getPreferredPreviewSizeForVideo() delegates to the getPreferredPreviewSizeForVideo() implementation on Camera.Parameters, except for devices known to return poor values for it.
what can I do to display an square? Maybe overlaying a square on top of CameraFragment?
I would try putting CameraView directly in your own UI, then layering something on top of it, using a FrameLayout or RelativeLayout to control the Z-axis ordering.

What is the relationship between screenSize, previewSize and pictureSize in Android camera?

I think many people feel confused like me between these few sizes.
Let me declare something: ratio = width/height.
In the surfaceView, we set previewSize and pictureSize as parameters.
But how to choose the best sizes??
If I want to capture a fullscreen image, what should the previewSize and pictureSize set to be?
There is some case that the preview is fullscreen but the saved image is bigger than the preview screen image, why?
Also, if the ratio of previewSize and pictureSize is different, is there any problems?
And, is it necessary to set the ratio of previewSize and screenSize the same?
To be honest, I just want to capture the fullscreen image and save it as jpg/png and the image saved is the exactly same width and height as preview, how to do it?
I just confused with the relationship between screenSize, previewSize and pictureSize.
Thank.
So let's start with the definitions, as I understand them.
ScreenSize: The physical dimensions of the physical display, this is the maximum size of pixels available to the device to display content to a user. This is pretty much a static value.
PreviewSize: This is usually the size of the image that an optical sensor can natively preview frames at a fast rate. The sensor usually provides a list of supported values. These are usually all the same aspect ratio. A supported previewSize may overlap with the ScreenSize. If so and you want to display a full size camera view, great! Whatever one that is, is the one you want. Otherwise it's probably just the closest value, up to you after that.
PictureSize: This is the size of the actual capture from the sensor. This is has nothing to do with either the other two values actually. It will usually overlap with some of the previewSize supported values for sure. But it can range much larger and have a much better resolution supported in general, as this is the final product after all. Many times the capture may look better on a device capable of displaying a better resolution than the ScreenSize Aspects of these can be different.
ScreenSize and PreviewSize are usually the most related to the presentation of the image while it is scanning for potential images. These are usually really unfocused quick renders of whatever the sensor is able to see at the moment and display them ot the user (almost like a video feed in a sense). In those cases you want to give the best possible, but sometimes the camera might not be setup to take full advantage of a display. I.e. a front facing camera is usually mounted in such a way that it is setup for capturing portrait type images and previews might not take advantage of the aspect ratio of the screen. This is purely cosmetic if you are not doing anything with the preview frames other than displaying them right to the screen. Otherwise it's more app specific at that point if this is a problem or not. Like for instance a front facing camera might have a 4:3 previewSize and the ScreenSize has a 16:9 ratio. You end up with the letterboxing or stretching solution which may be just right for what you are doing.
CaptureSize is usually not related to PreviewSize at all, as far as the developer is concerned. It's mildly related to ScreenSize only in cases where the captured file will only ever be displayed on the given device and never manipulated. I.e. if you only take images for this one app and only display them on this one app. IF the capture size is HUGE, and the screen is small, it's a little bit of a waste of space. On the other hand, if the capture is smaller than the screensize and the sole purpose is to just display the images on the screen, if the capture is smaller than the screen, you may have to scale up. It is usually more related to a tradeoff of memory, filesize, and quality of capture for manipulation later in some other activity or process.
Pretty much it comes down to this. High res is great if you have the bandwidth, storage and memory to do everything. If not you can always scale. If scaling, I prefer to scale down usually only because it often results in a better displayed image, as opposed to scaling up.
The more I am thinking about this, it's sort of a vague question overall. Hopefully this gives some benefit.

Categories

Resources