1

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.

EDIT

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

Community
  • 1
  • 1
Zar E Ahmer
  • 33,936
  • 20
  • 234
  • 300
  • To achieve grayscale preview, it may be enough to setup camera parameters with [`setColorEffect(Camera.parameters.EFFECT_MONO)`](http://developer.android.com/reference/android/hardware/Camera.Parameters.html#setColorEffect(java.lang.String)). – Alex Cohn Apr 20 '15 at 08:31
  • If you want more control, check *[Android: how to display camera preview with callback?](http://stackoverflow.com/questions/8350230/android-how-to-display-camera-preview-with-callback)* - actually, the question there is more informative than the attempts to answer it. – Alex Cohn Apr 20 '15 at 08:38

0 Answers0