Android拍照后显示照片
来源:互联网 发布:人员定位软件 编辑:程序博客网 时间:2024/05/01 11:39
mainActivity显示如下:
package cn.testcamera;import java.io.File;import java.text.SimpleDateFormat;import java.util.Date;import android.app.Activity;import android.content.Intent;import android.graphics.Bitmap;import android.graphics.BitmapFactory;import android.net.Uri;import android.os.Bundle;import android.provider.MediaStore;import android.view.View;import android.widget.Button;import android.widget.ImageView;public class MainActivity extends Activity {private Button mButton;private ImageView mImageView;private File mPhotoFile;private String mPhotoPath; public final static int CAMERA_RESULT=8888; public final static String TAG="xx";@Overridepublic void onCreate(Bundle savedInstanceState) {super.onCreate(savedInstanceState);setContentView(R.layout.main);mButton = (Button) findViewById(R.id.button);mButton.setOnClickListener(new ButtonOnClickListener());mImageView = (ImageView) findViewById(R.id.imageView);}private class ButtonOnClickListener implements View.OnClickListener {public void onClick(View v) {try {Intent intent = new Intent("android.media.action.IMAGE_CAPTURE");mPhotoPath="mnt/sdcard/DCIM/Camera/"+getPhotoFileName();mPhotoFile = new File(mPhotoPath);if (!mPhotoFile.exists()) {mPhotoFile.createNewFile();} intent.putExtra(MediaStore.EXTRA_OUTPUT, Uri.fromFile(mPhotoFile)); startActivityForResult(intent,CAMERA_RESULT);} catch (Exception e) {}}}private String getPhotoFileName() {Date date = new Date(System.currentTimeMillis());SimpleDateFormat dateFormat = new SimpleDateFormat("'IMG'_yyyyMMdd_HHmmss");return dateFormat.format(date) + ".jpg";}@Overrideprotected void onActivityResult(int requestCode, int resultCode, Intent data) {super.onActivityResult(requestCode, resultCode, data);if (requestCode==CAMERA_RESULT) { Bitmap bitmap = BitmapFactory.decodeFile(mPhotoPath, null); mImageView.setImageBitmap(bitmap);}}}
main.xml如下:
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent" android:layout_height="match_parent" > <Button android:id="@+id/button" android:layout_width="fill_parent" android:layout_height="wrap_content" android:text="点击按钮拍照" /> <ImageView android:id="@+id/imageView" android:layout_below="@id/button" android:layout_width="fill_parent" android:layout_height="wrap_content" /></RelativeLayout>
manifest.xml如下:
<manifest xmlns:android="http://schemas.android.com/apk/res/android" package="cn.testcamera" android:versionCode="1" android:versionName="1.0" > <uses-sdk android:minSdkVersion="8" android:targetSdkVersion="10" /> <uses-permission android:name="android.permission.CAMERA"/> <uses-permission android:name="android.permission.INTERNET" /> <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" /> <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" /> <application android:icon="@drawable/ic_launcher" android:label="@string/app_name" android:theme="@style/AppTheme" > <activity android:name=".MainActivity" android:launchMode="singleTask" android:label="@string/title_activity_main" > <intent-filter> <action android:name="android.intent.action.MAIN" /> <category android:name="android.intent.category.LAUNCHER" /> </intent-filter> </activity> </application></manifest>
- Android拍照后显示照片
- Android 拍照后显示照片
- Android 7.0调用相机拍照,返回后显示拍照照片
- android 开发 拍照后显示刚拍的照片
- Android拍照 图库照片本地显示
- Android 拍照,选取照片,截取,显示
- Android获取图片资源之——拍照后在程序中显示照片
- Android获取图片资源之——拍照后在程序中显示照片
- android 相机拍照后选择照片编辑,相片编辑界面直线形状会显示锯齿状
- android拍照选择图库后将照片剪裁压缩显示到imageview上
- Android获取图片资源之——拍照后在程序中显示照片
- 如何获得android手机拍照后照片的存放目录
- android 自定义用相机拍照后的照片存储位置
- Android手机拍照后照片被旋转的解决
- 部分Android手机拍照后照片被旋转的解决方案
- 部分Android手机拍照后照片被旋转的解决方案
- 部分Android手机拍照后照片被旋转的解决方案
- Android手机拍照后照片被旋转的解决方案
- 35岁之前成功的12条黄金法则
- Java中HashMap遍历的两种方式
- [疯狂Java讲义精粹] 第六章|Java集合
- ios 键盘遮住输入框
- 04_Interceptor
- Android拍照后显示照片
- 网易2013校园招聘笔试题
- c++ hash_map 详细介绍
- C++编程报告——WxWidget环境配置(IDE:CodeBlocks)
- tomcat下配置jdbc连sqlserver数据源( 采用jtds-1.1.jar驱动)
- UITableView的多个UITextField时,有的被键盘挡住怎么解决
- Ubuntu 12.04硬盘安装与U盘安装(图文)
- 期末口语考试
- fedora ftp 无法上传问题