0

我是安卓新手。camera我想制作一个可以使用对象拍照的应用程序。这是我的简单代码

public class Main extends Activity {
    Camera camera;
    ImageView iv;
    Button b;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        camera = camera.open();
        b = (Button) findViewById(R.id.bStartCamera);
        iv = (ImageView) findViewById(R.id.imageView1);
        b.setOnClickListener(new OnClickListener() {

            @Override
            public void onClick(View arg0) {
                if (camera != null) {
                    camera.takePicture(null, null, new CallBack());
                } else {
                    Log.d("", "Camera Object is Null");
                }

            }
        });

    }

    @Override
    protected void onPause() {
        // TODO Auto-generated method stub
        super.onPause();
        if (camera != null) {
            camera.release();
            camera = null;
        }
    }

    class CallBack implements PictureCallback {

        @Override
        public void onPictureTaken(byte[] data, Camera camera) {
            Log.d("", "In the Callback Method");
        }

    }

}

清单.xml

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="com.example.homescreensetter"
    android:versionCode="1"
    android:versionName="1.0" >

    <uses-sdk
        android:minSdkVersion="8"
        android:targetSdkVersion="10" />
    <uses-permission android:name="android.permission.CAMERA"/>

    <application
        android:allowBackup="true"
        android:icon="@drawable/ic_launcher"
        android:label="@string/app_name"
        android:theme="@style/AppTheme" >
        <activity
            android:name="com.example.homescreensetter.Main"
            android:label="@string/app_name" >
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />

                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>
    </application>

</manifest>

onPictureTaken我在我的设备上测试了这段代码,它有一个后置摄像头,但是当我拍照时,回调方法从未被调用过。请任何形式的帮助都会非常感谢,谢谢

4

0 回答 0