I forgot to mention that you need not do anything with the data returned from the PreviewCallback. Just calling setOneShotPreviewCallback is enough to trigger the problem. I'm not sure if my solution of using TextureView API getBitmap() will be sufficient in some cases since it doesn't give you the raw data from the camera, it gives you the scaled and processed bitmap backing the TextureView. At least it has the advantage of WYSIWYG for the image returned from TextureView getBitmap(), and no extra image processing required from my app.
I would still probably consider this a bug or a problem with the Nexus 5 camera driver. I have to install a KitKat build on my Nexus 4 to see if it's an actual problem in KitKat on other devices. On Fri, Nov 8, 2013 at 8:21 AM, Jon Sutherland <jon.sutherl...@gmail.com>wrote: > Hi, > > Thanks for your response. Note that I am using setOneShotPreviewCallback > to capture just one frame of the running preview and that I am also using > TextureView rather than SurfaceView. > > After some more investigation I see that the problem doesn't occur when > using the Camera with SurfaceView and calling setOneShotPreviewCallback. > So after digging through the TextureView API trying to find the problem I > see TextureView has a method called getBitmap() that does exactly what I > need anyway and doesn't cause the preview to go dark. So problem solved it > appears. Also a more correct and better use of the API :) > > > > On Friday, November 8, 2013 3:06:46 AM UTC-3:30, gjs wrote: >> >> Hi, >> >> One of my apps uses mCamera.setPreviewCallback(this); and onPreviewFrame( >> byte[] data, Camera camera) and its working OK on Nexus 5 with KRT16M >> build. >> >> Also the demo code you provided does nothing with the data from >> onPreviewFrame() >> >> Regards >> >> On Friday, November 8, 2013 11:15:20 AM UTC+11, Jon Sutherland wrote: >>> >>> There seems to be a problem on my Nexus 5 with KRT16M when taking a >>> frame from the camera using android.hardware.Camera >>> setOneShotPreviewCallback. The camera preview goes dark and the frame >>> saved is always dark. After the call happens the preview stays dark. This >>> is a real problem since the saved frames are so dark they're pretty >>> useless. The code below demonstrates the problem and runs fine on every >>> other device I've tried. It seems like a legitimate problem. Unless >>> anyone has an answer I'm going to file a bug soon. >>> >>> public class MainActivity extends Activity implements >>> SurfaceTextureListener { >>> >>> private Camera mCamera; >>> private TextureView mTextureView; >>> >>> @Override >>> protected void onCreate(Bundle savedInstanceState) { >>> super.onCreate(savedInstanceState); >>> >>> mTextureView = new TextureView(this); >>> mTextureView.setSurfaceTextureListener(this); >>> >>> setContentView(mTextureView); >>> >>> } >>> >>> @Override >>> public void onSurfaceTextureAvailable(SurfaceTexture surface, int width, >>> int height) { >>> mCamera = Camera.open(); >>> >>> Camera.Size previewSize = mCamera.getParameters().getPreviewSize(); >>> mTextureView.setLayoutParams(new FrameLayout.LayoutParams( >>> previewSize.width, previewSize.height, Gravity.CENTER)); >>> >>> try { >>> mCamera.setPreviewTexture(surface); >>> } catch (IOException t) { >>> } >>> >>> mCamera.startPreview(); >>> >>> Handler handler = new Handler(); >>> handler.postDelayed(new Runnable() { >>> @Override >>> public void run() { >>> mCamera.setOneShotPreviewCallback(new PreviewCallback() { >>> @Override >>> public void onPreviewFrame(byte[] data, Camera camera) { >>> >>> } >>> }); >>> } >>> }, 5000); >>> handler.postDelayed(new Runnable() { >>> @Override >>> public void run() { >>> mCamera.stopPreview(); >>> } >>> }, 10000); >>> handler.postDelayed(new Runnable() { >>> @Override >>> public void run() { >>> mCamera.startPreview(); >>> } >>> }, 15000); >>> } >>> >>> @Override >>> public void onSurfaceTextureSizeChanged(SurfaceTexture surface, int >>> width, >>> int height) { >>> } >>> >>> @Override >>> public boolean onSurfaceTextureDestroyed(SurfaceTexture surface) { >>> mCamera.stopPreview(); >>> mCamera.release(); >>> return true; >>> } >>> >>> @Override >>> public void onSurfaceTextureUpdated(SurfaceTexture surface) { >>> } >>> } >>> >>> >>> -- > You received this message because you are subscribed to the Google > Groups "Android Developers" group. > To post to this group, send email to android-developers@googlegroups.com > To unsubscribe from this group, send email to > android-developers+unsubscr...@googlegroups.com > For more options, visit this group at > http://groups.google.com/group/android-developers?hl=en > --- > You received this message because you are subscribed to a topic in the > Google Groups "Android Developers" group. > To unsubscribe from this topic, visit > https://groups.google.com/d/topic/android-developers/K-yiNXesF4c/unsubscribe > . > To unsubscribe from this group and all its topics, send an email to > android-developers+unsubscr...@googlegroups.com. > For more options, visit https://groups.google.com/groups/opt_out. > -- You received this message because you are subscribed to the Google Groups "Android Developers" group. To post to this group, send email to android-developers@googlegroups.com To unsubscribe from this group, send email to android-developers+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/android-developers?hl=en --- You received this message because you are subscribed to the Google Groups "Android Developers" group. To unsubscribe from this group and stop receiving emails from it, send an email to android-developers+unsubscr...@googlegroups.com. For more options, visit https://groups.google.com/groups/opt_out.