my problem.
I create app which do preview from camera on android.
For preview while im not press on button - i used Camera , camera.open. When app started - the orientation of screen is normal.. But when i try to record video - i closed camera preview and used only SurfaceView with recorder.setVideoSource(MediaRecorder.VideoSource.DEFAULT);
It's showing me preview from camera without class Camera.
All this i do becouse it's fixed for me bug with greenish screen after recorded.
So... this preview(which without camera) he after start always rotated on 90 degree ( Like in mode LANDSCAPE)
im try to use
setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE );
and
setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT );
but it not fixed my problem.
So, can any one tell me how to rotate my preview(without camera) in mode like SCREEN_ORIENTATION_PORTRAIT ??
pls tell me how to fix this problem.. i can't fix it 2-3 days :(
Regards, Peter
p.s. sorry for my bad english, hope u understand me.
it's code which i used for preview when i recorded video/audio
preview = new SurfaceView(withPreview.this);
preview.getHolder();
holder.addCallback(this);
holder.setType(SurfaceHolder.SURFACE_TYPE_PUSH_BUFFERS );
get picture from camera
recorder.setVideoSource(MediaRecorder.VideoSource.DEFAULT);
now the screen rotated on 90 degree. if i set
recorder.setVideoSource(MediaRecorder.VideoSource.CAMERA);
than image rotated on 180 degree О_О
and set preview
recorder.setPreviewDisplay(holder.getSurface());
that's all what i need for camera preview
How u can see im not using Camera.. so i can't us camera.parameters.setOrientation(90) //example
:]
is it right, that you will fix the Screen Orientation to Landscape or Portrait? Or should it be dynamic?
So if i understand you, to fix the orientation of the screen, then i prefer to add this into your Android Manifest:
android:screenOrientation="landscape"
This must inside the activity-block.
Hope this will help, otherwise tell me when it should dynmaic or so on.
Related
Hi I have different requirement. I want to open camera from android device which in black and white mode. I tried image color filter on ImageView but that's not suits. When i am writing that image in file as PDF the original color image has written in file. so instead color filter i wish to take picture in black and white mode.I searched and found the camera.parameter api but i don't know where to use it, when i tried that with Intent i am getting can't connect to the camera error message. I want to open camera in black and white mode and take pictures. Please help me
Thanks in advance
Camera Parameter api is when you are creating your own activity with camera mode and not using default camera application. You cannot start the camera in B&W mode using intents.
How to turn off device screen when front camera is covered with user finger, Can anybody tell how it will possible programmatically in android
For doing this, you need to keep camera on always. This will drain a lot of battery. If you still want to implement the same then you can check the image being formed in camera. If user covers the camera with finger/anything then image should be pure black. You can check color of all pixels of the image and then lock the screen accordingly.
Better way to do it will be by using proximity sensor and light sensor. Using camera consumes lot of battery and might not be accurate.
I hope I'm not late to the party but it seems what you looking for is the proximity sensor. Take a look at this https://github.com/williambout/react-native-proximity
I recording video using MediaRecorder.When using back-camera,it working fine,but when using front camera,the video captured is being flipped/inverse.Means that the item in right,will appear on the left.The camera preview is working fine,just final captured video flipped.
Here is the camera preview looks like
But the final video appear like this(all the item in left hand side,appear on right hand side)
What I tried so far:
I tried to apply the matrix when prepare recorder,but it seems does change anything.
private boolean prepareRecorder(int cameraId){
//# Create a new instance of MediaRecorder
mRecorder = new MediaRecorder();
setCameraDisplayOrientation(this,cameraId,mCamera);
int angle = getVideoOrientationAngle(this,cameraId);
mRecorder.setOrientationHint(angle);
if(cameraId == Camera.CameraInfo.CAMERA_FACING_FRONT){
Matrix matrix = new Matrix();
matrix.preScale(1.0f,-1.0f);
}
//all other code to prepare recorder here
}
I already read for all this question below,but all this seems didnt solve my problem.For information,I using SurfaceView for the camera preview,so this question here doesn't help.
1) Android flip front camera mirror flipped video
2) How to keep android from inverting the image from the front facing camera?
3) Prevent flipping of the front facing camera
So my question is :
1) How to capture a video by front camera which the video not being inverse(exactly the same with camera preview)?
2) How to achieve this when the Camera preview is using SurfaceView but not TextureView ? (cause all the question I mention above,tell about using TextureView)
All possible solution is mostly welcome..Tq
EDIT
I made 2 short video clip to clarify the problem,please download and take a look
1) The video during camera preview of recording
2) The video of the final product of recording
So, if the system camera app produces video similar to your app, you didn't do something wrong. Now it's time to understand what happens to front-facing camera video recording.
The front facing camera is not different from the rear facing camera in the way it captures still pictures or video. There is a difference how the phone displays camera preview on the screen. To make it look more natural to the user, Android (and all other systems) mirrors the preview, so that you can see yourself as if in a mirror.
It is important to understand that this only applies to the way the preview is presented to you. If you pick up any video conferencing app, connect two devices that you hold in two hands, and look at yourself, you will see to your surprise that the two instances of yourself are flipped.
This is not a bug, this is the natural way to present the video to the other party.
See the sketch:
This is how you see the scene:
This is how your peer sees the same scene
Normally, recording of a video is done from the point if view of your peer, as in the second picture. This is the natural setup for, e.g., video conferencing.
But Snapchat and some other social apps choose to store the front-facing video clip as if you record it from the mirror (as if the recorder is in your hand on the first picture). Some people like this feature, others hate it (see https://forums.androidcentral.com/general-help-how/664539-front-camera-pics-mirrored-reversed-only-snapchat.html and https://www.reddit.com/r/nexus6/comments/3846ay/has_anyone_found_a_fix_for_snapchat_flipping)
You cannot use MediaRecorder for that. You can use the lower-level API of MediaCodec to record processed frames. You need to flip each frame 'manually', and this may be a significant performance hit, because normally the MediaRecorder 'connects' the camera to hardware encoder in a very efficient way, without need even to copy the pixels to user memory. This answer shows how you can manipulate the way camera is rendered to texture.
You can achieve this by recording video manually from surface view.
In such case preview and recording will match exactly.
I've been using this library for this purpose:
https://github.com/spaceLenny/recordablesurfaceview
Here is the guide how to use it (not with camera but with OpenGL drawing): https://withintent.uncorkedstudios.com/recording-screen-video-on-android-with-recordablesurfaceview-451c9daa213e
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
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();