|
|
|
Android Camera2 API
Android Source Code
Java program for surveillance using an Android smartphone. Webcam with FTP access to the photo storage.
Android Safety SYSTEM >>
Let's see how to work with a camera - how to choose a camera, open, close, take a picture, choose a file size and format.
// == Camera2 API ===============================================
private void createCameraPreviewSession() {
mImageReader = ImageReader.newInstance(1920,1080, ImageFormat.JPEG,1); // The ImageReader class provides direct
// application access to the image data displayed in the surface
// If you set the image format to JPG, it will have a low FPS
// mImageReaderYUV = ImageReader.newInstance(1920,1080,ImageFormat.YUV_420_888,1);
mImageReader.setOnImageAvailableListener(mOnImageAvailableListener, null); // Callback interface to be notified when a new image is available
SurfaceTexture texture = mImageView.getSurfaceTexture();
texture.setDefaultBufferSize(1920,1080); // 1920,1080
Surface surface = new Surface(texture); //Создаем Surface
Log.i(LOG_TAG, "==| Create Surface |== in createCameraPreviewSession()");
try {
final CaptureRequest.Builder builder =
mCameraDevice.createCaptureRequest(CameraDevice.TEMPLATE_PREVIEW);
builder.addTarget(surface);
// In order to be able to view or take pictures, you need to create a session to work with the camera. Call the createCaptureSession () method for the selected camera.
mCameraDevice.createCaptureSession(Arrays.asList(surface,mImageReader.getSurface()),
new CameraCaptureSession.StateCallback() {
@Override
public void onConfigured(CameraCaptureSession session) { // Take a picture here
mCaptureSession = session;
try {
mCaptureSession.setRepeatingRequest(builder.build(),null,mBackgroundHandler);
Log.i(LOG_TAG, "==| private void onConfigured |== Camera Capture Session Success ");
} catch (CameraAccessException e) {
Log.i(LOG_TAG, "==| private void onConfigured |== Camera Capture Session Error ");
e.printStackTrace();
}
}
@Override
public void onConfigureFailed(CameraCaptureSession session) { }}, mBackgroundHandler);
} catch (CameraAccessException e) {
Log.i(LOG_TAG, "== | private void createCameraPreviewSession | == onConfigureFailed ");
e.printStackTrace();
}
}
CreateCameraPreviewSession
Here we are trying to output an image (data stream) to the mImageView texture, which is already defined in the layout activity_main.xml. You can even determine with what resolution in pixels.
Here we set the parameters of the picture - the JPG format, and the number of pixels.
mImageReader = ImageReader.newInstance(1920,1080, ImageFormat.JPEG,1); // The ImageReader class provides direct
mImageView.getSurfaceTexture() - getSurfaceTexture This method returns the SurfaceTexture used by this view
mImageView.getBitmap(int width, int height) - getBitmap(int width, int height) This method returns Returns a Bitmap representation of the content of the associated surface texture.
In order to use TextureView, all you need to do is get its SurfaceTexture.The SurfaceTexture can then be used to render content. In order to do this, you just need to do instantiate an object of this class and implement SurfaceTextureListener interface.
private TextureView myTexture;
public class MainActivity extends Activity implements SurfaceTextureListener{
protected void onCreate(Bundle savedInstanceState) {
myTexture = new TextureView(this);
myTexture.setSurfaceTextureListener(this);
setContentView(myTexture);
}
}
More information - www.tutorialspoint.com
The Texture is needed to work with the camera. The snapshot will be placed there. You can get its parameters - height, width and from the Texture save to file. How to write a picture to a file is discussed on the webpage dnl00016.htm
After that, you can create a connection to the FTP server and upload a picture.
Below are the links to the web pages with the source code for working with the FTP server.
Android Camera2 API
|
|
|
|
|
|
|
Application Rescue PHOTO has significant commercial potential. A huge number of old and damaged smartphones are sent to a distant box, landfill or recycling, without creating any cashback for you. Having zero cost, such smartphones can be used for photographic observation of objects via the Internet. Those. can be used to create low-cost commercial products. A company that creates such software can have positive dynamics in the market. Using the basic software product Rescue PHOTO in Java, you can create software for any needs of your customers.
Many useful functions can be added to the basic Java code based on additional agreements with clients. This allows you to monetize the free Rescue PHOTO remote surveillance app.
|
|
|
|