用户注册



邮箱:

密码:

用户登录


邮箱:

密码:
记住登录一个月忘记密码?

发表随想


还能输入:200字
云代码 - android代码库

surfaceview拍照加时间彩印

2014-09-04 作者: 風残月举报

[android]代码库

package com.dgchina.activity;

import com.dgchina.camera.CameraInterface;
import com.dgchina.camera.CameraInterface.CamOpenOverCallback;
import com.dgchina.preview.*;
import com.dgchina.util.DisplayUtil;
import com.example.playcamera.R;

import android.app.Activity;  
import android.graphics.Point;  
import android.os.Bundle;  
import android.view.Menu;  
import android.view.MotionEvent;
import android.view.SurfaceHolder;  
import android.view.View;  
import android.view.View.OnClickListener;  
import android.view.ViewGroup.LayoutParams;  
import android.view.Window;
import android.view.WindowManager;
import android.widget.Button;  
  
public class CameraActivity extends Activity implements CamOpenOverCallback {  
    private static final String TAG = "yanzi";  
    CameraSurfaceView surfaceView = null;  
    Button shutterBtn;  
    float previewRate = -1f;  
    @Override  
    protected void onCreate(Bundle savedInstanceState) {  
        super.onCreate(savedInstanceState);  
        Thread openThread = new Thread(){  
            @Override  
            public void run() {  
                // TODO Auto-generated method stub  
                CameraInterface.getInstance().doOpenCamera(CameraActivity.this);  
            }  
        };  
        openThread.start();  
        //去掉标题
        requestWindowFeature(Window.FEATURE_NO_TITLE);
        //设置全屏
        getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,WindowManager.LayoutParams.FLAG_FULLSCREEN);
        setContentView(R.layout.activity_main);  
        initUI();  
        initViewParams();  
          
        shutterBtn.setOnClickListener(new BtnListeners());  
    }  
  
    @Override  
    public boolean onCreateOptionsMenu(Menu menu) {  
        // Inflate the menu; this adds items to the action bar if it is present.  
       // getMenuInflater().inflate(R.menu.camera, menu);  
        return true;  
    }  
  
    private void initUI(){  
        surfaceView = (CameraSurfaceView)findViewById(R.id.camera_surfaceview);  
        shutterBtn = (Button)findViewById(R.id.btn_shutter);  
    }  
    private void initViewParams(){  
        LayoutParams params = surfaceView.getLayoutParams();  
        Point p = DisplayUtil.getScreenMetrics(this);  
        params.width = p.x;  
        params.height = p.y;  
        previewRate = DisplayUtil.getScreenRate(this); //默认全屏的比例预览  
        surfaceView.setLayoutParams(params);  
  
        //手动设置拍照ImageButton的大小为120dip×120dip,原图片大小是64×64  
//        LayoutParams p2 = shutterBtn.getLayoutParams();  
//        p2.width = DisplayUtil.dip2px(this, 80);  
//        p2.height = DisplayUtil.dip2px(this, 80);;        
//        shutterBtn.setLayoutParams(p2);   
  
    }  
  
    @Override  
    public void cameraHasOpened() {  
        // TODO Auto-generated method stub  
        SurfaceHolder holder = surfaceView.getSurfaceHolder();  
        CameraInterface.getInstance().doStartPreview(holder, previewRate);  
    }  
    private class BtnListeners implements OnClickListener{  
  
        @Override  
        public void onClick(View v) {  
            // TODO Auto-generated method stub  
            switch(v.getId()){  
            case R.id.btn_shutter:  
                //CameraInterface.getInstance().doTakePicture();  
                break;  
            default:break;  
            }  
        }  
  
    }
	@Override
	public boolean onTouchEvent(MotionEvent event) {
		// TODO Auto-generated method stub
		
		switch (event.getAction()) 
        {
        //触摸屏幕时刻
        case MotionEvent.ACTION_DOWN:
        	CameraInterface.getInstance().doTakePicture();  
           // Toast.makeText(MainActivity.this,"点击啦!",Toast.LENGTH_LONG).show();
            break;
        //触摸并移动时刻
        case MotionEvent.ACTION_MOVE:
        	//Toast.makeText(MainActivity.this,"移动中!",Toast.LENGTH_LONG).show();
        	break;
        //终止触摸时刻
        case MotionEvent.ACTION_UP:

        	break;
        }
		return super.onTouchEvent(event);
	}  
	
  
}  

[源代码打包下载]




网友评论    (发表评论)


发表评论:

评论须知:

  • 1、评论每次加2分,每天上限为30;
  • 2、请文明用语,共同创建干净的技术交流环境;
  • 3、若被发现提交非法信息,评论将会被删除,并且给予扣分处理,严重者给予封号处理;
  • 4、请勿发布广告信息或其他无关评论,否则将会删除评论并扣分,严重者给予封号处理。


扫码下载

加载中,请稍后...

输入口令后可复制整站源码

加载中,请稍后...