I have an application that scan barcode with the Android device cameras. I take the example program here: https://github.com/journeyapps/zxing-android-embedded
Now, I want to scan a barcode with my device front camera.
On that sample solution there's a button that allow you to take a barcode by front camera, but the problem is that the Preview image of camera is "flipped", like on a mirror, and so the application can't read the barcode.
Is there a method to overcome this problem and to make sure that the recorded image is displayed correctly?
This mirroring is hardcoded into the camera service, and can not be disabled.
Try applying a transformation matrix to a TextureView. As per Prevent flipping of the front facing camera
This works for API level >= 14
Related
I made a camera app with Camera2 API in Android, a fullscreen camera without taking pictures and I apply it a negative effect to all the preview, what I want to do is the negative effect only be applied to half of the preview, example:
Image Example
Here is my code:
Link to my code on github
I will appreciate the help because I am so lost i don't know what to do :(
Unfortunately, you'll have to do custom rendering here, since nothing in the camera2 or cameraX APIs will do this for you.
Basically, you'll need to send the camera output to the GPU, and use GL shader code to write your own custom negative effect.
That's a lot of boilerplate to get to where you want, but it's unlikely you'll have any other realistic option. While ImageView and some other Android UI APIs allow applying some effects or color transforms to their output, I don't think you could get them to give you half the view as negative, without significant performance problems.
To send camera image data to the GPU, use a SurfaceTexture as the output target, and then use the SurfaceTexture's texture ID in your EGL code as the source texture.
I'm using exoplayer in my project, when switching mediasource i just use
player.stop();
player.prepare(mediaSource);
This causes approx. 0.5 seconds black screen until it switches video.
Is there a way to tell exoplayer to retain last frame from previous video (instead of 0.5 sec black screen) until new video is started?
simpleExoPlayerView.setShutterBackgroundColor(Color.TRANSPARENT);
Exoplayer's developers have provided solution to this issue here.
Simply add this line using your SimplePlayerView instance
playerView.setKeepContentOnPlayerReset(true);
Alternatively, you can also do this via your layout.xml file,
app:keep_content_on_player_reset="true"
In my case I'm having a single instance on SimpleExoPlayer and i used to set this via setPlayer in exoplayer view with changed video url's but having blank screen when scroll back to previously played videos.
I just used setPlayer(null) before again setting the player in exoplayerview and the black screen issue fixed.
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