Camera Preview

by roscoe_x » Mon, 15 Jun 2009 04:35:19 GMT


Sponsored Links
 Camera Preview sample code in here:
 http://developer.android.com/guide/samples/ApiDemos/src/com/example/android/apis/graphics/CameraPreview.html 

My questions are:
1. There's an error in the program, in the try{} catch{} part in
surfaceCreated(). Any suggestions on how to solve this problem?
2. In the top part of the html page written "The file containing the
source code shown below is located in the corresponding directory in
<sdk>/platforms/android-<version>/samples/...". But I can not find the
sample code in that directory. Is the information wrong or my system
is incomplete?
3. What do I get (see) when the program run normally?

Thanks for the answer.

--~--~---------~--~----~------------~-------~--~----~



Camera Preview

by pat » Wed, 17 Jun 2009 01:49:36 GMT


 Hi everybody,

I implemented a camera preview SurfaceView that is loosely based on
the camera preview example from the android apis demo.

On the same activity, i have some live sensor readings displayed.

I always had the idea that the activity is running very slow and i
previously got some image freezings when I switched between two
different activities that both displayed the camera preview. That was
when I was building for SDK 1.1 today I migrated my application to 1.5
and catched the following error message:

06-15 23:56:26.272: ERROR/AndroidRuntime(726):
java.lang.RuntimeException: Out of memory
06-15 23:56:26.272: ERROR/AndroidRuntime(726):     at
android.hardware.Camera.native_setup(Native Method)
06-15 23:56:26.272: ERROR/AndroidRuntime(726):     at
android.hardware.Camera.<init>(Camera.java:82)
06-15 23:56:26.272: ERROR/AndroidRuntime(726):     at
android.hardware.Camera.open(Camera.java:64)

For clarity, I will post the code of my Preview class at the end.

Any idea what could be wrong?

Thanks a lot for your replies.

Patrick




package nl.uva.graffiti;

import android.content.Context;
import android.hardware.Camera;
import android.util.AttributeSet;
import android.view.SurfaceHolder;
import android.view.SurfaceView;

public classPreview extends SurfaceView implements
SurfaceHolder.Callback{

    SurfaceHolder mHolder;
    Camera mCamera;
    Context mContext;

    public Preview(Context context) {
        super(context);
        init();
    }

    public Preview (Context context, AttributeSet attrs){
        super(context, attrs);
        mContext = context;
        init();
    }

    public Preview(Context context, AttributeSet attrs, int defStyle){
        super(context, attrs, defStyle);
        init();
    }

    private void init(){
        mHolder = getHolder();
        mHolder.addCallback(this);
        mHolder.setType(SurfaceHolder.SURFACE_TYPE_PUSH_BUFFERS);
    }

    public void surfaceCreated(SurfaceHolder holder) {
        mCamera = Camera.open();
        try {
           mCamera.setPreviewDisplay(holder);
        } catch (Exception exception) {
            mCamera.release();
            mCamera = null;
        }
    }

    public void surfaceDestroyed(SurfaceHolder holder) {
        mCamera.stopPreview();
        mCamera = null;
    }

    public void surfaceChanged(SurfaceHolder holder, int format, int
w, int h) {
        Camera.Parameters parameters = mCamera.getParameters();
        parameters.setPreviewSize(w, h);
        mCamera.setParameters(parameters);
        mCamera.startPreview();
    }

}

--~--~---------~--~----~------------~-------~--~----~


Sponsored Links


Camera preview

by tinyang » Fri, 28 Aug 2009 03:43:28 GMT


 Hello.

I just got my camera preview working for my app, but it is not
appearing
where I want it to appear, and I'm not sure how to get it there.
Instead of
using the entire screen for the preview, I would like to put it inside
a
surfaceview in an activity xml gui.  What do I need to change?  Here
is my
code:

public class TakePic extends Activity {

SurfaceView camSurface;

Preview camPreview;

@Override

protected void onCreate(Bundle savedInstanceState) {

super.onCreate(savedInstanceState);

requestWindowFeature(Window.FEATURE_NO_TITLE);//hide window title

camPreview = new Preview(this); //create preview

setContentView(R.layout.takepic);

setContentView(camPreview); //set preview as activity content

camSurface = (SurfaceView) findViewById(R.id.camsurface);

}
--~--~---------~--~----~------------~-------~--~----~



Camera preview

by Pavel » Fri, 28 Aug 2009 16:00:12 GMT


 Hey tinyang,

Could you please share the code you use for picture taking? I am
working on the same thing and having weird issues with it - it does
not take full sized pictures for unknown reason...

And yeah, sorry, no answer to your question from my side at the moment.

Pavlo






--~--~---------~--~----~------------~-------~--~----~



Camera preview

by tinyang » Sat, 29 Aug 2009 03:50:52 GMT


 Hi Pavel, and thanks for the reply.  I'm happy to share the snippet of
code I have for picture taking, but I have not tried it out yet
because in order to see and use the picture-taking button in my
activity view, I need to get the camera preview in the correct place
first.

I still really need someone to help me on this please!! :)

Here is the code I was looking at trying, but I've done extensive
research on the subject trying to fix my placement of the camera
preview, so here are also some links that may help you with taking the
picture and storing it properly: (HTH!)

 http://www.devx.com/SpecialReports/Article/37721/1763?supportItem=5 

 http://www.devx.com/SpecialReports/Article/37721/1763? 

 http://www.anddev.org/viewtopic.php?p=704 #704

 http://www.androidph.com/2008/11/camera-capture.html 

 http://www.devx.com/SpecialReports/Article/37721/1954 

 http://www.cs.trincoll.edu/hfoss/wiki/Using_the_Android_camera 

Code:
public class ImageCaptureCallback implements PictureCallback  {

            private OutputStream filoutputStream;
            public ImageCaptureCallback(OutputStream filoutputStream) {
                this.filoutputStream = filoutputStream;
            }
            @Override
            public void onPictureTaken(byte[] data, Camera camera) {
                try {
                        Log.v(getClass().getSimpleName(), "onPictureTaken=" + 
data + "
length = " + data.length);
                        filoutputStream.write(data);
                        filoutputStream.flush();
                        filoutputStream.close();
                        } catch(Exception ex) {
                                ex.printStackTrace();
                        }
                }
            }
}





--~--~---------~--~----~------------~-------~--~----~



Camera preview

by Bill » Sat, 29 Aug 2009 09:23:13 GMT


 There seems to be a bug in the EXTRA_OPTIONS if you're using the
default camera activity. That is why you are not getting full sized
pictures.

If you want to embed the preview you can use the Camera object
directly.





--~--~---------~--~----~------------~-------~--~----~



Camera preview

by tinyang » Mon, 31 Aug 2009 21:42:55 GMT


 Thank you Bill for your response!  This has been confounding me for a
while and I've had no idea how to remedy it.  Is it possible for you
to please include a code sample or a link to a code sample?





--~--~---------~--~----~------------~-------~--~----~



Re: Camera preview

by Mark Murphy » Fri, 11 Feb 2011 20:20:56 GMT


 That example has a flaw -- it hard-wires in /sdcard as the location of
external storage. Use File.getExternalStorageDirectory() for that
instead, or some other spot.

Here is another sample project:

https://github.com/commonsguy/cw-advandroid/tree/master/Camera/Picture

This one is more complex, because it uses a front-facing camera on
Android 2.3+, but otherwise it does the same basic things as the
example you cited.






-- 
Mark Murphy (a Commons Guy)
 http://commonsware.com  |  http://github.com/commonsguy 
 http://commonsware.com/blog  |  http://twitter.com/commonsguy 

Android App Developer Books:  http://commonsware.com/books 

-- 



Other Threads

1. android 1.5r2 manifest fixed

We recently noticed a bug we've had in the android_1.5r2 manifest
where it was using the latest version of cupcake instead of one
specific version.

I've just deployed a corrected version of that manifest so that it
permanently matches the android_1.5r2 code. If you've been working
from android_1.5r2 and synced your client from the Android Open-Source
Project since early July, you should sync again to get back to the
proper version.

Apologies about the inconvenience. I'll be changing our process in the
future to avoid such situations.

JBQ

(PS: the android-1.5r2 tag on the manifest is currently incorrect,
I'll try to make it point to the right commit. The tags on the
individual projects are correct).

-- 
Jean-Baptiste M. "JBQ" Queru
Software Engineer, Android Open-Source Project, Google.

Questions sent directly to me that have no reason for being private
will likely get ignored or forwarded to a public forum with no further
warning.

--~--~---------~--~----~------------~-------~--~----~
unsubscribe: android-porting+unsubscr...@googlegroups.com
website: 

2. Unable to unlock using keyboard in Android in the desktop screen

You need to have a key map file that describes which key generates the menu
key code, so you can press it to unlock.  Or modify the keyguard (the phone
policy in frameworks/policies/base) to do something more appropriate for
your hardware.






-- 
Dianne Hackborn
Android framework engineer
hack...@android.com

Note: please don't send private questions to me, as I don't have time to
provide private support, and so won't reply to such e-mails.  All such
questions should be posted on public forums, where I and others can see and
answer them.

--~--~---------~--~----~------------~-------~--~----~
unsubscribe: android-porting+unsubscr...@googlegroups.com
website: 

3. Silent install on first boot

4. ListView: invisible dividers still take up space. Is it a bug or a feature?

5. how to implement OTA service ?

6. Multicast receive broken in Android 1.5?

7. ListView: invisible dividers still take up space. Is it a bug or a feature?