Android_通过Intent调用系统相机和相册回传bitmap
来源:互联网 发布:java sftp上传文件 编辑:程序博客网 时间:2024/06/10 08:47
main.xml
<?xml version="1.0" encoding="utf-8"?><LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layout_height="match_parent" android:orientation="vertical" > <ImageView android:id="@+id/takePhoto_imageView" android:layout_margin="50dp" android:layout_width="200dp" android:layout_height="200dp" android:layout_gravity="center" android:src="@drawable/ic_launcher"/> <Button android:layout_marginTop="90px" android:id="@+id/takePhoto_bt1" android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_gravity="center" android:textSize="20sp" android:textStyle="bold" android:text="拍照"/> <Button android:id="@+id/takePhoto_bt2" android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_gravity="center" android:textSize="20sp" android:textStyle="bold" android:text="从相册选择照片"/></LinearLayout>
MainActivity.java
package com.lxf;import java.io.FileNotFoundException;import android.app.Activity;import android.content.ContentResolver;import android.content.Intent;import android.graphics.Bitmap;import android.graphics.BitmapFactory;import android.os.Bundle;import android.util.Log;import android.view.View;import android.widget.ImageView;/** * @address BeiJing * @author LiXufei * @function 拍照取图相册取图 */public class cTakePhoto extends Activity{ private ImageView imageView; private int TAKE_PHOTO=1; //拍照 private int GET_PHOTO=2; //取照片 @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.android_takephoto); //获取ImageView控件 imageView = (ImageView) findViewById(R.id.takePhoto_imageView); /* * 拍照取图 */ findViewById(R.id.takePhoto_bt1).setOnClickListener(new View.OnClickListener() { public void onClick(View v) { //设置拍照意图 Intent mIntent = new Intent(android.provider.MediaStore.ACTION_IMAGE_CAPTURE); startActivityForResult(mIntent, TAKE_PHOTO); } }); /* * 相册取图 */ findViewById(R.id.takePhoto_bt2).setOnClickListener(new View.OnClickListener() { public void onClick(View v) { Intent intent = new Intent(Intent.ACTION_GET_CONTENT); intent.setType("image/*"); startActivityForResult(intent, GET_PHOTO); } }); } //接受回传值 @Override protected void onActivityResult(int requestCode, int resultCode, Intent data) { super.onActivityResult(requestCode, resultCode, data); if (resultCode == RESULT_OK) { //回传值接受成功 if (requestCode == TAKE_PHOTO) { //拍照取图 Bundle bundle = data.getExtras(); //获取data数据集合 Bitmap bitmap = (Bitmap) bundle.get("data"); //获得data数据 Log.i("TAG", "拍照回传bitmap:"+bitmap); imageView.setImageBitmap(bitmap); } if (requestCode == GET_PHOTO) { //相册取图 ContentResolver contentResolver = getContentResolver(); try { Bitmap bitmap = BitmapFactory.decodeStream(contentResolver.openInputStream(data.getData())); Log.i("TAG", "从相册回传bitmap:"+bitmap); imageView.setImageBitmap(bitmap); } catch (FileNotFoundException e) { e.printStackTrace(); } } } }}
1 0
- Android_通过Intent调用系统相机和相册回传bitmap
- 调用系统相册和相机
- 通过隐式Intent调用相册和调用相机 获取图片
- 调用系统相册和调用相机
- 调用系统相册和系统相机拍照
- 调用系统相机相册
- 调用系统相册,相机
- 调用系统相机相册
- 调用系统相机拍照和选择相册
- iOS开发 调用系统相机和相册
- 调用系统的相机和相册
- android 调用系统相机和相册
- iOS 调用系统相机和相册
- Android调用系统相机和相册
- Android调用系统相机和相册-填坑篇
- Android调用系统相机和相册
- Android调用系统相机和相册
- android调用系统相机和相册
- Android Service进阶教程
- Sublime Text3使用技巧
- 非常全面的浏览器useragent判断代码
- Mac下SVN账号删除更换终极解决方法,百度都是坑爹的
- 用python修改haproxy配置文件
- Android_通过Intent调用系统相机和相册回传bitmap
- 十. Linux中bash shell的使用
- test
- python 高阶函数
- 行业短信应用的类型与短信模板
- Plsql解除试用期
- C语言学习入门到精通之学习笔记(三)
- 树莓派安装mysql 及开通远程访问设置
- spring 事物隔离级别和传播行为