How to do effective coding in Camera PreviewCallback

I have to create grey Scale camera live Preview. It is working fine. But i want to make the code faster.

private android.hardware.Camera.PreviewCallback previewCallback = new android.hardware.Camera.PreviewCallback() { public void onPreviewFrame(byte abyte0[] , Camera camera) { Size size = cameraParams.getPreviewSize(); int[] rgbData = YuvUtils.decodeGreyscale(abyte0, size.width, size.height); Bitmap bitmapung = Bitmap.createBitmap(rgbData, size.width, size.height, Bitmap.Config.ARGB_8888); Bitmap bitmapToSet = Bitmap.createBitmap(bitmapung, 0, 0, widthPreview, heightPreview, matrix, true); MyActivity.View.setBitmapToDraw(bitmapToSet); };

  1. As i am creating Bitmap object twice.Can i do this job with one bitmap Object.
  2. where (on which method like onResume or onCreate) should i getCamera Size(means width and height once). So that i don't need to set it for each callback.
  3. And I know i should use AsyncTask to do it. I will do it after solving my current issue.


I can create bitmap while getting Camera Size(width,height). Then single instance of bitmap is associated to my Class. but i have to call setPixels for it.

bitmapung.setPixels(rgbData, offset, stride, x, y, size.width, size.height);

What should I set the values of Stride ,offset and x,y. And also explain them plz.

Also have a look on these questions also

Create custom Color Effect

Add thermal effect to yuvImage

Category:android Views:4 Time:2018-03-08

Related post

Copyright (C), All Rights Reserved.

processed in 0.126 (s). 11 q(s)