This week I worked on implementing the camera functionality of our product. Simulating the camera was a bit hard, but in the end I was able to do it in a proper way successfully.
First we have to make things clear. Android does not use the web cam to simulate the camera but when you correctly implemented it, you will get a default image from the platform and this will prove us that we are on the right way. First we have to give permission to the application to use camera functionality. We do it by adding “
Then we will get a camera from the system.
mCamera = Camera.open();
We will set the parameters of the camera:
Camera.Parameters params = mCamera.getParameters();
mSize = params.getPictureSize();
params.setPictureFormat(PixelFormat.JPEG);
mCamera.setParameters(params);
Then, we have to implement the callback function of the camera:
Camera.PictureCallback photoCallback = new Camera.PictureCallback() {
public void onPictureTaken(byte[] data, Camera camera) {
writeTextOnPicture(data);
}
};
With the above function we will get the default picture as a byte array. We will convert it to Bitmap object then will set the view to that image and we are done.
No comments:
Post a Comment