看过的书和提示,摆脱了所有的编译错误和警告,并把一些调试语句摄像头预览:没有错误,但没有图像:-(
package com.cit.BroadcastSim;
import java.io.IOException;
import android.app.Activity;
import android.hardware.Camera;
import android.os.Bundle;
import android.util.Log;
import android.view.SurfaceHolder;
import android.view.SurfaceView;
public class BroadcastActivity extends Activity implements SurfaceHolder.Callback {
public Camera myCamera;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.broadcast); // Inflate the broadcast.xml file
Log.d("BROADCAST", "Creating the Activity");
SurfaceView cameraSurface = (SurfaceView)findViewById(R.id.camerasurface);
SurfaceHolder cameraHolder = cameraSurface.getHolder();
cameraHolder.setType(SurfaceHolder.SURFACE_TYPE_PUSH_BUFFERS);
cameraHolder.addCallback(this);
Log.d("BROADCAST", "Now wait for some CallBacks");
}
public void surfaceCreated(SurfaceHolder holder) {
// Surface created, now it is possible to set the preview
Log.d("BROADCAST", "Surface Created");
try {
Log.d("BROADCAST","CAMERA: NOT NULL");
myCamera = Camera.open();
myCamera.setPreviewDisplay(holder);
myCamera.startPreview();
} catch (IOException e) {
Log.d("BROADCAST", e.getMessage());
}
}
public void surfaceDestroyed(SurfaceHolder holder) {
Log.d("BROADCAST", "Surface Destroyed");
myCamera.stopPreview();
myCamera.release();
}
public void surfaceChanged(SurfaceHolder holder, int I, int J, int K) {
Log.d("BROADCAST", "Surface Changed");
myCamera.stopPreview();
myCamera.release();
}
}
在DDMS调试器,我得到一个'创建活动'的日志消息,后面跟着'现在等待一些CallBacks',就我的调试消息而言,没有什么更多的了,所以我认为回调不起作用 - 因为我的生活看不到它出错的地方。
在清单我
的活动XML页面有
<TextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="@string/Broadcast"
/>
<SurfaceView
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:id="@+id/camerasurface"
/>
</LinearLayout>
最后,Android手机(HTC野火)上,页面加载,显示在左上角的TextView的消息,这是所有。
应该提及的是,我对这个平台很陌生,并且认为我可能错过了非常基本的东西。
任何意见/建议,我将非常感激,
奥利弗
嗨,已经设法解决我的问题的seom - 基本上关闭SurfaceChanged()中的所有东西,但你的泥土是非常漂亮的。今天晚上将花费在它上面,以确保我能够正确理解它,然后再实施它。因为它是人类交互实验的一部分,所以请在纵向视图中设置相机。非常感谢您的反馈,谢谢。 – LenseOnLife 2011-01-27 15:39:12