续:http://topic.csdn.net/u/20120518/14/00457380-e333-46f8-9d7f-8eee0d82e3b9?45849
转自:http://dev.10086.cn/cmdn/bbs/thread-39389-1-2
(5)能够预览了,接下来就是拍照了,拍照用到了一个camera.tackPiture()这个方法,这个方法,有三个参数分别是
ShutterCallBack shutter,PictureCallBack raw,PictureCallBack jpeg.
下面是对他们的实现
01 private ShutterCallback shutter = new ShutterCallback() {
02
03 @Override
04 public void onShutter() {
05 // TODO Auto-generated method stub
06 Log.d("ddd", "shutter");
07
08 }
09 };
10 private PictureCallback raw = new PictureCallback() {
11
12 @Override
13 public void onPictureTaken(byte[] data, Camera camera) {
14 // TODO Auto-generated method stub
15 Log.d("ddd", "raw");
16
17 }
18 };
19 private PictureCallback jpeg = new PictureCallback() {
20
21 @Override
22 public void onPictureTaken(byte[] data, Camera camera) {
23 // TODO Auto-generated method stub
24 Log.d("ddd","jpeg");
25
26 }
27 };
当开始拍照时,会依次调用shutter的onShutter()方法,raw的onPictureTaken方法,jpeg的onPictureTaken方法.
三个参数的作用是shutter--拍照瞬间调用,raw--获得没有压缩过的图片数据,jpeg---返回jpeg的图片数据
当你不需要对照片进行处理,可以直接用null代替.
注意,当调用camera.takePiture方法后,camera关闭了预览,这时需要调用startPreview()来重新开启预览。
我用以上知识,加到上面的那个例子,就形成了下面的代码:
MySurfaceView.javaview sourceprint?01 package com.wjh.camera;
02 import java.io.IOException;
03 import android.content.Context;
04 import android.graphics.PixelFormat;
05 import android.hardware.Camera;
06 import android.hardware.Camera.PictureCallback;
07 import android.hardware.Camera.ShutterCallback;
08 import android.util.Log;
09 import android.view.SurfaceHolder;
10 import android.view.SurfaceView;
11 public class MySurfaceView extends SurfaceView implements SurfaceHolder.Callback{
12 SurfaceHolder holder;
13 Camera myCamera;
14 private ShutterCallback shutter = new ShutterCallback() {
15
16 @Override
17 public void onShutter() {
18 // TODO Auto-generated method stub
19 Log.d("ddd", "shutter");
20
21 }
22 };
23 private PictureCallback raw = new PictureCallback() {
24
25 @Override
26 public void onPictureTaken(byte[] data, Camera camera) {
27 // TODO Auto-generated method stub
28 Log.d("ddd", "raw");
29
30 }
31 };
32 private PictureCallback jpeg = new PictureCallback() {
33
34 @Override
35 public void onPictureTaken(byte[] data, Camera camera) {
36 // TODO Auto-generated method stub