看過的書和提示,擺脫了所有的編譯錯誤和警告,並把一些調試語句攝像頭預覽:沒有錯誤,但沒有圖像:-(
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