I've spent the last two days browsing SO to find answers, unsuccessfully.
I'm trying to reproduce a Snapchat-like app.
What I have so far
A ViewPager composed of 3 fragments.
The middle fragment is supposed to display a camera preview, just like Snapchat, on the whole surface (not truly fullscreen but it should cover the entire UI between the status bar and the bottoms buttons)
I'm able to display either:
The camera preview, with the correct ratio, but not covering its parent View (see picture 1 below)
The camera preview, covering its parent View but stretched (wrong ratio)
What I need
Avoid stretching the preview. Possibly, the preview would be cropped on both sides (left and right). See picture 2 below. I guess this is what Snapchat does. Or is there any other way?
What I went through
http://www.shakedos.com/2015/Aug/26/writing-an-android-portrait-camera-app.html
Make a SurfaceView larger than the screen (Fitting a camera preview to a SurfaceView larger than the display)
Android full screen camera - while keeping the camera selected ratio : can't find the whole code
Requirements
I need to use the Camera API version 1, not version 2.
Final photos must be taken in 4/3 format, not 16/9.
Portrait is forced although pictures can be in landscape or portrait
Thank you
Related
iI want to create a app to crop a part of picture exactly after taking a picture in camera app, like this image:
But I don't know how.
First of all you need to configure camera preview with Android Camera(2) API. (example for more details).
Next put your preview surface in FrameLayout and add view over preview surface to draw crop rectangle.
Crop image using, for example, Bitmap.createBitmap(source, left, top, width, height). Read more. (If you configured camera for jpg output you should first decode captured image.)
Developing an app for Android and I'm required to have a fullscreen image rotate (spin around infinitely, pivoted at the centre of the screen) in the background.
I have tried rotating the ImageView using RotateAnimation which works well, except the image is cropped to the size of the parent view.
I have also tried expanding the parent view to a set size (750dp) but it doesn't work well across all the different screen sizes.
Does anyone know of an easy way to implement this, which would involve scaling to uniformly fit the screen size?
Cheers,
Dylan
Screenshot of the image:
I'm creating an Android application which adds frames to images (Think those things at the beach that you stick your head in...), but I want the image to show on top of the surface view holding the camera feed so that the user can position the subject of the photo.
The problem I'm having is that the camera feed (the surface view) is showing either side of the image. I want to re-size the surface view to fit the image. The size of the image may vary.
I think you like to have some overlay on top of surface view - this is achieved with frame layout like this:
http://javaocr.svn.sourceforge.net/viewvc/javaocr/trunk/demos/sampler/res/layout/main.xml?revision=229&view=markup
You can place everything but other surface view in the overlay
I am trying to build a custom camera view which fills the whole screen by stretching the preview while maintaining the aspect ratio and having the parts outside the screen cropped. I have been unable to get the surface view which the camera uses to stretch larger than the screen size. I can get it to be smaller than the screen, or have it stretched to match the screen exactly which ruins the aspect ratio. How do I go about getting the camera to fill the screen without losing the aspect ratio?
For some reason the camera feed in my program is sideways. If I hold my finger up to the camera from the bottom, it shows up as coming from the right in the surfaceview.
I have a pretty standard implementation
surfaceView = (SurfaceView)findViewById(R.id.surfaceView);
surfaceHolder = surfaceView.getHolder();
surfaceHolder.addCallback(surfaceCallback);
surfaceHolder.setType(SurfaceHolder.SURFACE_TYPE_PUSH_BUFFERS);
I've looked around but I can't seem to find any information on this. My device is a nexus One.
EDIT: If I set the screen orientation to landscape then it works fine for some reason... Can't get it in portrait though.
The orientation of the preview display image is controlled by Camera.setDisplayOrientation(int) method. For my Evo, setting the orientation to 90 makes the preview display correct for portrait mode.
...
camera.setParameters(parameters);
camera.setDisplayOrientation((orientation+90)%360);
camera.startPreview();
...
It seems that changing the orientation after the preview is started causes an exception. If you change rotate the phone/device, the SurfaceHolder.surfaceChanged callback will be called again, if you do the setDisplayOrientation and startPreview in that callback, you get an exception. I'm, going to try stopping preview, then changing the orientation then starting it again.
Note: There is also the Camera.Parameters.setRotation(int) method, that (I think) changes the orientation of the image when it is written into the (JPEG) output image when a picture is taken. This method does not change the preview display orientation.
use this line
mCamera.setDisplayOrientation(90);
in surfaceCreated method after
mCarmera.open();