提交 f97e5f73 编写于 作者: A Andrey Kamaev

Modified Android samples

上级 87ad9b1c
......@@ -50,7 +50,7 @@ class Sample1View extends SampleViewBase implements SurfaceHolder.Callback {
@Override
protected Bitmap processFrame(byte[] data)
{
Log.e("SAMP1", "processFrame begin");
//Log.e("SAMP1", "processFrame begin");
mYuv.put(0, 0, data);
......@@ -83,7 +83,7 @@ class Sample1View extends SampleViewBase implements SurfaceHolder.Callback {
Bitmap bmp = Bitmap.createBitmap(mFrameWidth, mFrameHeight, Bitmap.Config.ARGB_8888);
android.MatToBitmap(mRgba, bmp);
Log.e("SAMP1", "processFrame end");
//Log.e("SAMP1", "processFrame end");
return bmp;
}
......
......@@ -52,15 +52,16 @@ public abstract class SampleViewBase extends SurfaceView implements SurfaceHolde
}
public void surfaceCreated(SurfaceHolder holder) {
Log.i("SAMP1", "surfaceCreated");
mCamera = Camera.open();
mCamera.setPreviewCallback(
new PreviewCallback() {
public void onPreviewFrame(byte[] data, Camera camera) {
synchronized(SampleViewBase.this) {
mFrame = data;
Log.i("SAMP1", "before notify");
//Log.i("SAMP1", "before notify");
SampleViewBase.this.notify();
Log.i("SAMP1", "after notify");
//Log.i("SAMP1", "after notify");
}
}
}
......@@ -69,6 +70,7 @@ public abstract class SampleViewBase extends SurfaceView implements SurfaceHolde
}
public void surfaceDestroyed(SurfaceHolder holder) {
Log.i("SAMP1", "surfaceDestroyed");
mThreadRun = false;
if(mCamera != null) {
synchronized(this) {
......@@ -87,22 +89,26 @@ public abstract class SampleViewBase extends SurfaceView implements SurfaceHolde
Log.i(TAG, "Starting thread");
Bitmap bmp = null;
while(mThreadRun) {
Log.i("SAMP1", "before synchronized");
//Log.i("SAMP1", "before synchronized");
synchronized(this) {
Log.i("SAMP1", "in synchronized");
//Log.i("SAMP1", "in synchronized");
try {
this.wait();
Log.i("SAMP1", "before processFrame");
//Log.i("SAMP1", "before processFrame");
bmp = processFrame(mFrame);
Log.i("SAMP1", "after processFrame");
//Log.i("SAMP1", "after processFrame");
} catch (InterruptedException e) {
e.printStackTrace();
}
}
Canvas canvas = mHolder.lockCanvas();
canvas.drawBitmap(bmp, (canvas.getWidth()-mFrameWidth)/2, (canvas.getHeight()-mFrameHeight)/2, null);
mHolder.unlockCanvasAndPost(canvas);
if (bmp != null){
Canvas canvas = mHolder.lockCanvas();
if (canvas != null){
canvas.drawBitmap(bmp, (canvas.getWidth()-mFrameWidth)/2, (canvas.getHeight()-mFrameHeight)/2, null);
mHolder.unlockCanvasAndPost(canvas);
}
}
}
}
}
\ No newline at end of file
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册