gpt4 book ai didi

android - 相机开启时在 SurfaceView 上绘制

转载 作者:行者123 更新时间:2023-11-29 00:39:35 26 4
gpt4 key购买 nike

我有以下访问相机预览的代码我想在预览图片的上角显示一些文本我该怎么做?

package com.gps.ro.capturetest;

import java.io.IOException;

import android.app.Activity;
import android.content.pm.ActivityInfo;
import android.content.pm.PackageManager;
import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.Paint;
import android.graphics.PixelFormat;
import android.hardware.Camera;
import android.hardware.Camera.CameraInfo;
import android.hardware.Camera.PictureCallback;
import android.hardware.Camera.ShutterCallback;
import android.os.Bundle;
import android.util.Log;
import android.view.SurfaceHolder;
import android.view.SurfaceView;
import android.view.View;
import android.view.Window;
import android.view.WindowManager;

public class CaptureTestActivity extends Activity implements SurfaceHolder.Callback {
SurfaceHolder mSurfaceHolder;
SurfaceView mSurfaceView;
public Camera mCamera;
boolean mPreviewRunning;
Canvas test;

@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
getWindow().setFormat(PixelFormat.TRANSLUCENT);
requestWindowFeature(Window.FEATURE_NO_TITLE);
getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
WindowManager.LayoutParams.FLAG_FULLSCREEN);
setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);
setContentView(R.layout.main);
mSurfaceView = (SurfaceView) findViewById(R.id.camera_surface);
mSurfaceHolder = mSurfaceView.getHolder();
mSurfaceHolder.addCallback(this);
mSurfaceHolder.setType(SurfaceHolder.SURFACE_TYPE_PUSH_BUFFERS);




}

public void surfaceChanged(SurfaceHolder arg0, int arg1, int h, int w) {
// TODO Auto-generated method stub
if (mPreviewRunning) {
mCamera.stopPreview();
}
Camera.Parameters p = mCamera.getParameters();
mCamera.setDisplayOrientation(90);
p.setPreviewSize(h, w);
p.set("orientation", "portrait");

//p.setPreviewSize(w, h);
mCamera.setParameters(p);
try {
mCamera.setPreviewDisplay(arg0);

} catch (IOException e) {
e.printStackTrace();
}
mCamera.startPreview();
mPreviewRunning = true;

}

public void surfaceCreated(SurfaceHolder arg0) {
// TODO Auto-generated method stub
mCamera = Camera.open();
}

public void surfaceDestroyed(SurfaceHolder arg0) {
// TODO Auto-generated method stub
mCamera.stopPreview();
mPreviewRunning = false;
mCamera.release();
}

public void Trigger(View V)
{
ShutterCallback shutterCallback = new ShutterCallback() {
public void onShutter() {
Log.d("DHA", "onShutter'd");
}
};

PictureCallback rawCallback = new PictureCallback() {
public void onPictureTaken(byte[] data, Camera camera) {
Log.d("DHA", "onPictureTaken - raw");
}


};
Log.w("DHA", "Intra aici!");
mCamera.takePicture(shutterCallback, rawCallback, null);

}







}

最佳答案

在表面 View 之上创建另一个 View ,并在该 View 中绘制装饰。例如,您可以使用 FrameLayout 并在其中使用 SurfaceView,然后在预览顶部添加您想要的 View 。

关于android - 相机开启时在 SurfaceView 上绘制,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10295229/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com