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 [email protected]
To unsubscribe from this group, send email to
[email protected]
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 [email protected].
For more options, visit https://groups.google.com/groups/opt_out.