Android Camera拍照
来源:互联网 发布:百分百营销软件总站 编辑:程序博客网 时间:2024/04/25 12:14
//开始拍照
private void startCamera() {
File dir = new File(Environment.getExternalStorageDirectory(), "img");
if (!dir.exists()) {
dir.mkdirs();
}
String fileName = System.currentTimeMillis() + ".jpg";
imgFile = new File(dir, fileName);
if (!imgFile.exists()) {
try {
imgFile.createNewFile();
} catch (IOException e) {
e.printStackTrace();
}
}
if (!imgFile.exists()) {
imgFile.mkdirs();
}
//在此传入参数Extra_output,直接返回图片可能太大或者是模糊
Intent intent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
intent.putExtra(MediaStore.EXTRA_OUTPUT, Uri.fromFile(imgFile));
startActivityForResult(intent, 100);
}
//拍照回来
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
switch (requestCode) {
case 100:
if (imgFile == null) {
Toast.makeText(this, "img file == null", Toast.LENGTH_LONG).show();
return;
}
// imgView.setImageURI(Uri.fromFile(imgFile));
Options options = new BitmapFactory.Options();
options.inJustDecodeBounds = true;
BitmapFactory.decodeFile(imgFile.getAbsolutePath(), options);
int outWidth = options.outWidth;
int outHeight = options.outHeight;
Log.e(TAG, "height = " + outHeight);
Log.e(TAG, "width = " + outWidth);
options.inJustDecodeBounds = false;
options.inSampleSize = 4;
// 缩小的倍数
Bitmap bitmap2 = BitmapFactory.decodeFile(imgFile.getAbsolutePath(), options);
//有些手机系统会把图片自动旋转,如果有旋转,需要转回来
int degrees = readPictureDegree(imgFile.getAbsolutePath());
//图片处理类
Matrix matrix = new Matrix();
matrix.postRotate(degrees);
Bitmap bitmap = Bitmap.createBitmap(bitmap2, 0, 0, bitmap2.getWidth(), bitmap2.getHeight(), matrix, true);
imgView.setImageBitmap(bitmap);
break;
default:
break;
}
}
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
switch (requestCode) {
case 100:
if (imgFile == null) {
Toast.makeText(this, "img file == null", Toast.LENGTH_LONG).show();
return;
}
// imgView.setImageURI(Uri.fromFile(imgFile));
Options options = new BitmapFactory.Options();
options.inJustDecodeBounds = true;
BitmapFactory.decodeFile(imgFile.getAbsolutePath(), options);
int outWidth = options.outWidth;
int outHeight = options.outHeight;
Log.e(TAG, "height = " + outHeight);
Log.e(TAG, "width = " + outWidth);
options.inJustDecodeBounds = false;
options.inSampleSize = 4;
// 缩小的倍数
Bitmap bitmap2 = BitmapFactory.decodeFile(imgFile.getAbsolutePath(), options);
//有些手机系统会把图片自动旋转,如果有旋转,需要转回来
int degrees = readPictureDegree(imgFile.getAbsolutePath());
//图片处理类
Matrix matrix = new Matrix();
matrix.postRotate(degrees);
Bitmap bitmap = Bitmap.createBitmap(bitmap2, 0, 0, bitmap2.getWidth(), bitmap2.getHeight(), matrix, true);
imgView.setImageBitmap(bitmap);
break;
default:
break;
}
}
//读取图像的旋转角度
public int readPictureDegree(String path) {
int degree = 0;
try {
ExifInterface exifInterface = new ExifInterface(path);
int orientation = exifInterface.getAttributeInt(ExifInterface.TAG_ORIENTATION,
ExifInterface.ORIENTATION_NORMAL);
switch (orientation) {
case ExifInterface.ORIENTATION_ROTATE_90:
degree = 90;
break;
case ExifInterface.ORIENTATION_ROTATE_180:
degree = 180;
break;
case ExifInterface.ORIENTATION_ROTATE_270:
degree = 270;
break;
}
} catch (IOException e) {
e.printStackTrace();
}
return degree;
}
public int readPictureDegree(String path) {
int degree = 0;
try {
ExifInterface exifInterface = new ExifInterface(path);
int orientation = exifInterface.getAttributeInt(ExifInterface.TAG_ORIENTATION,
ExifInterface.ORIENTATION_NORMAL);
switch (orientation) {
case ExifInterface.ORIENTATION_ROTATE_90:
degree = 90;
break;
case ExifInterface.ORIENTATION_ROTATE_180:
degree = 180;
break;
case ExifInterface.ORIENTATION_ROTATE_270:
degree = 270;
break;
}
} catch (IOException e) {
e.printStackTrace();
}
return degree;
}
0 0
- android camera 后台拍照
- Android Camera进行拍照
- Android之Camera拍照
- android Camera拍照
- Android Camera进行拍照
- Android+Camera+拍照
- Android Camera拍照实现
- Android Camera 无法拍照
- Android Camera拍照
- Android之Camera拍照
- Android照相机拍照Camera
- Android camera拍照分辨率
- android相机camera拍照
- android camera无预览拍照 后台拍照
- Android Camera拍照常见问题小结
- Android Camera拍照常见问题小结
- Android Camera——拍照
- Android调用Camera摄像机拍照
- 堆排序
- [Java JVM] Hotspot GC研究- GC安全点 (Safepoint&Stop The World)
- Oracle 导出、导入某用户所有数据(包括表、视图、存储过程...)
- 一.angularJs——服务调用与后台数据获取
- 非常LOW的负面炒作 没事看看吧
- Android Camera拍照
- Recurrent Neural Networks 循环神经网络
- Tree-DFS(Depth-First-Search)
- c++ ifstream直接转换为浮点数
- wget命令
- 算法的时间复杂度和空间复杂度-总结
- 6.0视频电话流程
- UVA11324 The Largest Clique (强联通+缩点+DAG上DP最长路)
- 在ES6类中绑定事件