Android 简单的照相机程序
2010-12-18 08:03:41 来源:WEB开发网终于经过多次找错,修改把一个简单的照相机程序完成了,照相类代码如下:
代码
1 class surface extends SurfaceView implements SurfaceHolder.Callback {
2
3 SurfaceHolder sfholder;
4
5 Camera camera;
6
7 Bitmap bitmap;
8
9 public surface(Context context) {
10 super(context);
11 // TODO Auto-generated constructor stub
12
13 sfholder = getHolder();
14 sfholder.addCallback(this);
15 sfholder.setType(SurfaceHolder.SURFACE_TYPE_PUSH_BUFFERS);
16 }
17
18 public void surfaceChanged(SurfaceHolder holder, int format, int width,
19 int height) {
20 // TODO Auto-generated method stub
21 Camera.Parameters parameters = camera.getParameters();
22 parameters.setPictureFormat(PixelFormat.JPEG);
23 parameters.setPreviewSize(320, 480);
24 parameters.setPictureSize(320, 480);
25 camera.setParameters(parameters);
26 camera.startPreview();
27 }
28
29 public void surfaceCreated(SurfaceHolder holder) {
30 // TODO Auto-generated method stub
31
32 try {
33 camera = Camera.open();
34 camera.setPreviewDisplay(sfholder);
35 } catch (Exception e) {
36 camera.release();
37 camera = null;
38 }
39 }
40
41 public void surfaceDestroyed(SurfaceHolder holder) {
更多精彩
赞助商链接