相机camera,出错,error camera error 100
mainactivity.javapackage com.example.shootyou;
import java.io.IOException;
import android.app.Activity;
import android.hardware.Camera;
import android.os.Bundle;
import android.view.Su易做图ceHolder;
import android.view.Su易做图ceView;
import android.view.Window;
public class MainActivity extends Activity {
private Camera camera;
@SuppressWarnings("deprecation")
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
requestWindowFeature(Window.FEATURE_NO_TITLE);
setContentView(R.layout.activity_main);
Su易做图ceView sv=(Su易做图ceView)findViewById(R.id.su易做图ce1);
final Su易做图ceHolder sh=sv.getHolder();
sh.setType(Su易做图ceHolder.SURFACE_TYPE_PUSH_BUFFERS);
camera=Camera.open();
try {camera.setPreviewDisplay(sh);
/* Camera.Parameters parameters=camera.getParameters();*/
camera.startPreview();
camera.autoFocus(null);
}catch(IOException e){
e.printStackTrace();
}
}
@Override
protected void onPause() {
// TODO 自动生成的方法存根
camera.stopPreview();
camera.release();
super.onPause();
}
}
manifest.xml
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.shootyou"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk
android:minSdkVersion="8"
android:targetSdkVersion="17" />
<uses-permission android:name="android.permission.CAMERA"/>
<uses-feature android:name="android.hardware.camera"/>
<uses-feature android:name="android.hardware.camera.autofocus"/>
<application
android:allowBackup="true"
android:icon="@drawable/ic_launcher"
android:label="@string/app_name"
android:theme="@style/AppTheme" >
<activity
android:name="com.example.shootyou.MainActivity"
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>
布局文件
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingBottom="@dimen/activity_vertical_margin"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
tools:context=".MainActivity" >
<Su易做图ceView
android:id="@+id/su易做图ce1"
android:layout_width="match_parent"
android:layout_height="match_parent"/>
<ImageView
android:id="@+id/gun1"
android:contentDescription="@string/gun"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@drawable/gun"
android:layout_gravity="bottom|center_vertical"/>
</FrameLayout>
运行后提示错误
10-14 13:47:45.598: E/Camera(1615): Error 100
10-14 13:54:53.738: I/Choreographer(1615): Skipped 47 frames! The application may be doing too much work on its main thread.
看问题的意思好像说是相机的帧数太多,相对主进程太大,不知道局地问题是哪里,请指教,我只是想获取摄像头预览,并不需要照相,存取相片,因此就没有对内存卡权限声明,应该不会影响吧 摄像头 内存 Camera --------------------编程问答-------------------- http://stackoverflow.com/questions/8647628/android-camera-server-died-and-camera-error-100/9929683照这个改一下试试。
Skipped 47 frames!是说有47条log没抓到,原因可能是UI主线程干的活太多了,建议把耗时操作放到新线程里。
补充:移动开发 , Android