How to take a photo and send to HTTP POST request with Android?

This link should be more than sufficient for clicking, saving and getting path of an image: Capture Images This is the class i wrote for uploading images via HTTP POST: public class MultipartServer { private static final String TAG = “MultipartServer”; private static String crlf = “\r\n”; private static String twoHyphens = “–“; private static … Read more

Android: detect brightness (amount of light) in phone’s surroundings using the camera?

Here is how you register a listener on the light sensor: private final SensorManager mSensorManager; private final Sensor mLightSensor; private float mLightQuantity; public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); // Obtain references to the SensorManager and the Light Sensor mSensorManager = (SensorManager)getSystemService(SENSOR_SERVICE); mLightSensor = mSensorManager.getDefaultSensor(Sensor.TYPE_LIGHT); // Implement a listener to receive updates SensorEventListener listener = … Read more

iphone image captured from camera rotate -90 degree automatically

you have to use this function to rotate image captured by camera – (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingImage:(UIImage *)image editingInfo:(NSDictionary *)editingInfo { image = [self scaleAndRotateImage:image]; [self useImage:image]; [[picker parentViewController] dismissModalViewControllerAnimated:YES]; } – (void)scaleAndRotateImage:(UIImage *)image { int kMaxResolution = 320; // Or whatever CGImageRef imgRef = image.CGImage; CGFloat width = CGImageGetWidth(imgRef); CGFloat height = CGImageGetHeight(imgRef); CGAffineTransform transform … Read more

What is the difference between `opencv.android.JavaCameraView` and `opencv.android.NativeCameraView`

From the OpenCV documentation: The org.opencv.android.JavaCameraView class is implemented inside OpenCV library. It is inherited from CameraBridgeViewBase, that extends SurfaceView and uses standard Android camera API. Alternatively you can use org.opencv.android.NativeCameraView class, that implements the same interface, but uses VideoCapture class as camera access back-end. opencv:show_fps=”true” and opencv:camera_id=”any” options enable FPS message and allow to … Read more

android: Take camera picture without “save” / “delete” confirmation

You ca use the SurfaceView to capture image package com.camera; import java.io.IOException; import android.app.Activity; import android.content.Intent; import android.hardware.Camera; import android.os.Bundle; import android.util.Log; import android.view.SurfaceHolder; import android.view.SurfaceView; import android.view.View; import android.widget.Button; import android.widget.Toast; public class Camera_capture extends Activity implements SurfaceHolder.Callback { private Camera mCamera; private SurfaceView surfaceView; private SurfaceHolder surfaceHolder; private Button capture_image; @Override protected void … Read more

How to check if camera is opened by any application

If your device API version is higher than 21, CameraManager.AvailabilityCallback might be a good choice. You need to first obtain the camera manager of the system with the following code: CameraManager manager = (CameraManager) getSystemService(Context.CAMERA_SERVICE); Then, you need to register the AvailabilityCallback: CameraManager manager = (CameraManager) getSystemService(Context.CAMERA_SERVICE); if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) { manager.registerAvailabilityCallback(new CameraManager.AvailabilityCallback() { … Read more

Take a picture on iPhone without showing controls

EDIT: As suggested in the comments below, I have now explicitly shown how the AVCaptureSession needs to be declared and initialized. It seems that a few were doing the initialization wrong or declaring AVCaptureSession as a local variable in a method. This would not work. Following code allows to take a picture using AVCaptureSession without … Read more

switch back/front camera on fly

In onCreate() of my activity I add the following onClick listener to a button overlayed on my Preview SurfaceView (there are numerous example on the web for previewing): ImageButton useOtherCamera = (ImageButton) findViewById(R.id.useOtherCamera); //if phone has only one camera, hide “switch camera” button if(Camera.getNumberOfCameras() == 1){ useOtherCamera.setVisibility(View.INVISIBLE); } else { useOtherCamera.setOnClickListener(new View.OnClickListener() { @Override public … Read more

Compress camera image before upload

Take a look over here: ByteArrayOutputStream to a FileBody Something along these lines should work: replace File file = new File(miFoto); ContentBody foto = new FileBody(file, “image/jpeg”); with Bitmap bmp = BitmapFactory.decodeFile(miFoto) ByteArrayOutputStream bos = new ByteArrayOutputStream(); bmp.compress(CompressFormat.JPEG, 70, bos); InputStream in = new ByteArrayInputStream(bos.toByteArray()); ContentBody foto = new InputStreamBody(in, “image/jpeg”, “filename”); If file size … Read more