来自anddev

import android.app.Activity; import android.content.Context; import android.graphics.Canvas; import android.graphics.Color; import android.graphics.Paint; import android.hardware.Camera; import android.os.Bundle; import android.view.SurfaceHolder; import android.view.SurfaceView; import android.view.View; import android.view.Window; import android.view.ViewGroup.LayoutParams; public class TestCameraOverlay extends Activity { /** Called when the activity is first created. */ @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); requestWindowFeature(Window.FEATURE_NO_TITLE); Preview mPreview = new Preview(this); DrawOnTop mDraw = new DrawOnTop(this); setContentView(mPreview); addContentView(mDraw, new LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT)); } } class DrawOnTop extends View { public DrawOnTop(Context context) { super(context); // TODO Auto-generated constructor stub } @Override protected void onDraw(Canvas canvas) { // TODO Auto-generated method stub Paint paint = new Paint(); paint.setStyle(Paint.Style.FILL); paint.setColor(Color.BLACK); canvas.drawText("Test Text", 10, 10, paint); super.onDraw(canvas); } } class Preview extends SurfaceView implements SurfaceHolder.Callback { SurfaceHolder mHolder; Camera mCamera; Preview(Context context) { super(context); // Install a SurfaceHolder.Callback so we get notified when the // underlying surface is created and destroyed. mHolder = getHolder(); mHolder.addCallback(this); mHolder.setType(SurfaceHolder.SURFACE_TYPE_PUSH_BUFFERS); } public void surfaceCreated(SurfaceHolder holder) { // The Surface has been created, acquire the camera and tell it where // to draw. mCamera = Camera.open(); mCamera.setPreviewDisplay(holder); } public void surfaceDestroyed(SurfaceHolder holder) { // Surface will be destroyed when we return, so stop the preview. // Because the CameraDevice object is not a shared resource, it's very // important to release it when the activity is paused. mCamera.stopPreview(); mCamera = null; } public void surfaceChanged(SurfaceHolder holder, int format, int w, int h) { // Now that the size is known, set up the camera parameters and begin // the preview. Camera.Parameters parameters = mCamera.getParameters(); parameters.setPreviewSize(w, h); mCamera.setParameters(parameters); mCamera.startPreview(); } } Parsed in 0.113 seconds, using GeSHi 1.0.8.4

更多相关文章

  1. Android客户端接收来自Faye的消息推送
  2. Viewpageindicator inside fragment
  3. Android的Socket通信编程实例
  4. VLC for Android(安卓)on Linux
  5. Vue JS 与Android(安卓)webview的交互
  6. Android(安卓)汉字转拼音之工具篇
  7. 内存管理Memory Management in Android
  8. 内存管理Memory Management in Android
  9. Android横竖屏切换不重新调用onCreate()

随机推荐

  1. 用小鸟云服务器搭建网站常用的伪静态设置
  2. Vue 中的 .sync 修饰符stop修饰符prevent
  3. MVC架构模式思想
  4. 硬盘亮黄灯没有及时处理?服务器数据恢复案
  5. PHP初识字符串
  6. 一些小例子
  7. 聊一聊如何把SSL证书安装到小鸟云服务器
  8. 关于开发视图
  9. 小鸟云服务器 新增香港高防云服务器,抵御D
  10. VMWARE ESX SERVER虚拟化数据恢复过程总