使用内置的Camera应用程序捕获图像
来源:互联网 发布:linux 自建邮局 编辑:程序博客网 时间:2024/06/06 04:05
package com.example.day01;import android.content.ContentResolver;import android.content.Intent;import android.graphics.Bitmap;import android.graphics.BitmapFactory;import android.media.Image;import android.net.Uri;import android.os.Environment;import android.provider.MediaStore;import android.support.annotation.IntegerRes;import android.support.v7.app.AppCompatActivity;import android.os.Bundle;import android.util.Log;import android.widget.ImageView;import java.io.File;import java.io.FileNotFoundException;import java.net.URI;/** * 音视频联系一:使用内置的Camera应用程序捕获图像 */public class MainActivity extends AppCompatActivity { private final int CAMERA_RESULT = 0; ImageView view = null; Uri uri; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); String imagePath = Environment.getExternalStorageDirectory().getAbsolutePath() + File.separator + "capture1.jpg"; File imageFile = new File(imagePath); uri = Uri.fromFile(imageFile); Intent intent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE); //打开相机// intent.putExtra(MediaStore.EXTRA_OUTPUT, uri); //通过uri方式将图片存起来与getImgFromCamera()使用 startActivityForResult(intent, CAMERA_RESULT); } @Override protected void onActivityResult(int requestCode, int resultCode, Intent intent) { super.onActivityResult(requestCode, resultCode, intent); if (resultCode == RESULT_OK) { Bundle extras = intent.getExtras(); if (extras != null) { Bitmap bitmap = (Bitmap) extras.get("data"); view = (ImageView) findViewById(R.id.backImage); view.setImageBitmap(bitmap); //显示一个小图像 }// getImgFromCamera(); //通过uri的方式去获取得到的图片 } } /** * 通过uri的方式去获取得到的图片 */ private void getImgFromCamera() { ContentResolver cr = this.getContentResolver(); Bitmap cameraBitmap = null; try { if (cameraBitmap != null) cameraBitmap.recycle();// 如果不释放的话,不断取图片,将会内存不够 cameraBitmap = BitmapFactory.decodeStream(cr.openInputStream(uri)); view = (ImageView) findViewById(R.id.backImage); view.setImageBitmap(cameraBitmap); } catch (FileNotFoundException e) { Log.e("error", "从相机中获取图片失败====="); e.printStackTrace(); } }}
0 0
- 使用内置的Camera应用程序捕获图像
- 使用内置的Camera应用程序捕获图像
- Android 使用内置的Camera应用程序捕获图像
- Android 使用内置的Camera应用程序捕获图像
- 使用内置的Camera捕获图像
- Android使用内置Camera应用程序进行图像捕获
- Android图像处理简介の使用内置Camera应用程序进行图像捕获
- 使用内置的Camera应用程序
- 使用Camera类, 旋转90预览图像的问题
- 捕获应用程序所有的异常
- 构建自己的Camera应用程序
- 构建自定义的Camera应用程序
- 保存一张捕获的图像
- Android Camera的图像处理
- Android多媒体学习十五:使用在内置的Camera录制视频
- Android多媒体学习十五:使用在内置的Camera录制视频
- 使用OpenCV从视频中捕获图像
- 使用FFmpeg捕获一帧摄像头图像
- zabbix之日志文件监控
- Java服务器端+Android端(验证用户登录)
- react native Text 使用详解
- Android报错:Caused by: java.lang.IllegalArgumentException: Service Intent must be explicit: Intent
- 南阳理工ACM 题目252 01串
- 使用内置的Camera应用程序捕获图像
- linux内核理解学习笔记一
- MySQL运行状态show status中文详解
- Qt中的三种基类
- iOS之NSArray使用集合
- Process Stats:了解你的APP如何使用内存
- 关于java中静态变量初始化
- linux按照文件后缀进行排序
- Android-EditText(自定义带删除功能的EditText)