Android 应用拍照
来源:互联网 发布:巨人网络老板 编辑:程序博客网 时间:2024/06/06 02:34
- 申请权限
<uses-feature android:name="android.hardware.camera" android:required="true" />
- 检查相机是否可以使用
hasSystemFeature(PackageManager.FEATURE_CAMERA).
- 获取照片
static final int REQUEST_IMAGE_CAPTURE = 1;private void dispatchTakePictureIntent() { Intent takePictureIntent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE); if (takePictureIntent.resolveActivity(getPackageManager()) != null) { startActivityForResult(takePictureIntent, REQUEST_IMAGE_CAPTURE); }}
- 获取照片缩略图
@Overrideprotected void onActivityResult(int requestCode, int resultCode, Intent data) { if (requestCode == REQUEST_IMAGE_CAPTURE && resultCode == RESULT_OK) { Bundle extras = data.getExtras(); Bitmap imageBitmap = (Bitmap) extras.get("data"); mImageView.setImageBitmap(imageBitmap); }}
- 设置唯一名称
String mCurrentPhotoPath;private File createImageFile() throws IOException { // Create an image file name String timeStamp = new SimpleDateFormat("yyyyMMdd_HHmmss").format(new Date()); String imageFileName = "JPEG_" + timeStamp + "_"; File storageDir = Environment.getExternalStoragePublicDirectory( Environment.DIRECTORY_PICTURES); File image = File.createTempFile( imageFileName, /* prefix */ ".jpg", /* suffix */ storageDir /* directory */ ); // Save a file: path for use with ACTION_VIEW intents mCurrentPhotoPath = "file:" + image.getAbsolutePath(); return image;}
- 直接保存在本地
static final int REQUEST_TAKE_PHOTO = 1;private void dispatchTakePictureIntent() { Intent takePictureIntent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE); // Ensure that there's a camera activity to handle the intent if (takePictureIntent.resolveActivity(getPackageManager()) != null) { // Create the File where the photo should go File photoFile = null; try { photoFile = createImageFile(); } catch (IOException ex) { // Error occurred while creating the File ... } // Continue only if the File was successfully created if (photoFile != null) { takePictureIntent.putExtra(MediaStore.EXTRA_OUTPUT, Uri.fromFile(photoFile)); startActivityForResult(takePictureIntent, REQUEST_TAKE_PHOTO); } }}
- 加载图片缩略图
private void setPic() { // Get the dimensions of the View int targetW = mImageView.getWidth(); int targetH = mImageView.getHeight(); // Get the dimensions of the bitmap BitmapFactory.Options bmOptions = new BitmapFactory.Options(); bmOptions.inJustDecodeBounds = true; BitmapFactory.decodeFile(mCurrentPhotoPath, bmOptions); int photoW = bmOptions.outWidth; int photoH = bmOptions.outHeight; // Determine how much to scale down the image int scaleFactor = Math.min(photoW/targetW, photoH/targetH); // Decode the image file into a Bitmap sized to fill the View bmOptions.inJustDecodeBounds = false; bmOptions.inSampleSize = scaleFactor; bmOptions.inPurgeable = true; Bitmap bitmap = BitmapFactory.decodeFile(mCurrentPhotoPath, bmOptions); mImageView.setImageBitmap(bitmap);}
0 0
- Android 应用拍照
- Android多媒体应用开发-控制摄像头拍照
- Android多媒体应用开发-控制摄像头拍照
- Android 第三方应用使用拍照功能
- android中 camera 拍照应用详解
- 【Android应用开发技术:媒体开发】拍照
- Android 多媒体应用:调用摄像头拍照
- Android多媒体应用开发系列(一) 拍照
- Android拍照
- android拍照
- android拍照
- android 拍照
- android拍照
- android拍照
- Android拍照
- Android拍照
- Android拍照
- android拍照
- find ----linux文件查找
- swift 服务端要求json对象怎么办?(一)
- 自己写的一个测试RAC LoadBalance的shell脚本
- PhoneGap问题积累
- 图基本算法 图搜索基于邻接表的(广度优先、深度优先)
- Android 应用拍照
- 从程序员到CTO的Java技术路线图
- 如何拉起被一键清除的安卓进程
- 界面的功能特色---菜单栏和工具栏
- java工厂模式
- RPC请求处理过程
- Android -- 跨应用启动Service
- 【前端JS】js 转换 Long 格式时间为 Date 格式时间
- js实现单向链表