Android调用Camera实现自定义照相
2013-09-07 21:09:00 来源:WEB开发网package com.nico;
import java.io.ByteArrayInputStream;
import java.io.IOException;
import android.app.Activity;
import android.content.Context;
import android.graphics.PixelFormat;
import android.graphics.drawable.BitmapDrawable;
import android.graphics.drawable.Drawable;
import android.hardware.Camera;
import android.os.Bundle;
import android.os.Environment;
import android.util.Log;
import android.view.SurfaceHolder;
import android.view.SurfaceView;
import android.view.View;
import android.view.Window;
import android.view.WindowManager;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.LinearLayout;
public class Test extends Activity implements OnClickListener {
/** Called when the activity is first created. */
// camera 类
private Camera camera = null;
// 继承surfaceView的自定义view 用于存放照相的图片
private CameraView cv = null;
// 回调用的picture,实现里边的onPictureTaken方法,其中byte[]数组即为照相后获取到的图片信息
private Camera.PictureCallback picture = new Camera.PictureCallback() {
@Override
public void onPictureTaken(byte[] data, Camera camera) {
// 主要就是将图片转化成drawable,设置为固定区域的背景(展示图片),当然也可以直接在布局文件里放一个surfaceView供使用。
ByteArrayInputStream bais = new ByteArrayInputStream(data);
Drawable d = BitmapDrawable.createFromStream(bais, Environment
更多精彩
赞助商链接