0

I need to get preview from camera and show it on Imageview.. The code is done as follows

public void onPreviewFrame(byte[] data, Camera camera){
        yuvimage = new YuvImage(data, parameters.getPreviewFormat(), width, height, null);
        yuvimage.compressToJpeg(new Rect(0,0,parameters.getPreviewSize().width,parameters.getPreviewSize().height), 90, outstr);
        bmp = BitmapFactory.decodeByteArray(outstr.toByteArray(), 0, outstr.size());        
        camera.addCallbackBuffer(data);
    }

This code works fine, the if bmp passed to imageview the it displays clear color image on most of the devices, but on a tablet, it shows green/pink image.. If surfaceview is used to show preview directly then it shows clear color preview on all devices..

Any suggestion is appreciated..

Ichigo Kurosaki
  • 3,765
  • 8
  • 41
  • 56
  • I'm not sure what you mean by "clear color". Are colors being changed from (say) red to blue? Can you post sample images? See also http://stackoverflow.com/questions/13703596/mediacodec-and-camera-colorspaces-dont-match – fadden Feb 13 '14 at 16:02

1 Answers1

0

If the image looks sort of correct, but just has a weird color to it, then I would guess that the problem lies with the picture format. I would start is by trying to change parameters.getPreviewFormat() to ImageFormat.NV21 and see if that fixes the problem.

I have used basically the same code before, and never had a problem. (Although you should push the rendering to a separate thread, and probably use RenderScript to convert the pictures).

bremen_matt
  • 6,902
  • 7
  • 42
  • 90