基本信息
源码名称:使用camera拍照源码下载(自定义camera类)
源码大小:0.99M
文件格式:.zip
开发语言:Java
更新时间:2014-05-15
友情提示:(无需注册或充值,赞助后即可获取资源下载链接)
嘿,亲!知识可是无价之宝呢,但咱这精心整理的资料也耗费了不少心血呀。小小地破费一下,绝对物超所值哦!如有下载和支付问题,请联系我们QQ(微信同号):813200300
本次赞助数额为: 2 元×
微信扫码支付:2 元
×
请留下您的邮箱,我们将在2小时内将文件发到您的邮箱
源码介绍
自定义camera进行拍照
自定义camera进行拍照
package com.example.cameratest;
import java.io.File;
import java.util.UUID;
import android.app.Activity;
import android.content.pm.ActivityInfo;
import android.content.res.Configuration;
import android.os.Bundle;
import android.os.Environment;
import android.util.DisplayMetrics;
import android.util.Log;
import android.view.Menu;
import android.view.SurfaceView;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
public class MainActivity extends Activity {
private Button btn1;
private SurfaceView surfaceView;
private CameraHelper cameraHelper;// 相机类
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
btn1 = (Button) findViewById(R.id.btn1);
surfaceView = (SurfaceView) findViewById(R.id.surfaceview);
String fileName =System.currentTimeMillis() ".jpg";
String filePath = Environment.getExternalStorageDirectory()
.getPath() File.separator
"SMTPDB/Images" File.separator fileName;
cameraHelper = new CameraHelper(surfaceView, getApplicationContext(),filePath);
btn1.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
if (cameraHelper != null) {
//cameraHelper.setStartPhone(true);
//cameraHelper.setOrientation(getPhoneOrientation());
cameraHelper.CameraPicture();
}
}
});
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.main, menu);
return true;
}
@Override
public void onConfigurationChanged(Configuration newConfig) {
// TODO Auto-generated method stub
super.onConfigurationChanged(newConfig);
int test = 0;
Log.i("Test", "onConfigurationChanged");
}
/**
* 确认手机是横屏还是竖屏:1竖屏,2横屏
*
* @return
*/
public int getPhoneOrientation() {
int result = 0;
int t = getRequestedOrientation();
if (t == ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE) { // 横屏
result = 2;
} else if (t == ActivityInfo.SCREEN_ORIENTATION_PORTRAIT) { // 竖屏
result = 1;
}
int t1 = this.getResources().getConfiguration().orientation;
if (t1 == Configuration.ORIENTATION_LANDSCAPE) {
// 横屏
result = 2;
} else if (t1 == Configuration.ORIENTATION_PORTRAIT) {
// 竖屏
result = 1;
}
DisplayMetrics dm = new DisplayMetrics();
getWindowManager().getDefaultDisplay().getMetrics(dm);
int width = dm.widthPixels;
int height = dm.heightPixels;
if (width > height) {
// 横屏
result = 2;
} else {
// 竖屏
result = 1;
}
return result;
}
}