I am creating an Android API where developers can use my class to take a picture. But how can I return a Bitmap using onPictureTaken. Check out my code, please:
This is the mainActivity button:
button.setOnClickListener(new OnClickListener() { @Override public void onClick(View v) {
And here is my CameraUtils class:
public class CameraUtils implements Camera.PictureCallback { private Camera mCamera = null; private SurfaceTexture surfaceTexture = new SurfaceTexture(0); public Bitmap takePicture() { try { mCamera = Camera.open(1); Camera.Parameters params = mCamera.getParameters(); List<Camera.Size> sizes = params.getSupportedPictureSizes(); params.setPictureFormat(ImageFormat.JPEG); params.setPictureSize(sizes.get(0).width, sizes.get(0).height); mCamera.setParameters(params); mCamera.setPreviewTexture(surfaceTexture); mCamera.startPreview(); Log.i("MyCamera", "before takePicture"); new Handler().postDelayed(new Runnable() { @Override public void run() { mCamera.takePicture(null, null, CameraUtils.this); } }, 1000);
What do I need to do to get one Bitmap using my class method?
Thanks.
source share