阅读:https://developer.android.com/training/camera/index.html

先学学怎么从相机获取相片。

首先要有权限:

<manifest ... ><uses-feature android:name="android.hardware.camera" />...
</manifest ... >

private void dispatchTakePictureIntent(int actionCode) {Intent takePictureIntent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);startActivityForResult(takePictureIntent, actionCode);
}

//查询是否有程序能够照相
public static boolean isIntentAvailable(Context context, String action) {final PackageManager packageManager = context.getPackageManager();final Intent intent = new Intent(action);List<ResolveInfo> list =packageManager.queryIntentActivities(intent, PackageManager.MATCH_DEFAULT_ONLY);return list.size() > 0;
}

//获取Bitmap并显示
private void handleSmallCameraPhoto(Intent intent) {Bundle extras = intent.getExtras();mImageBitmap = (Bitmap) extras.get("data");mImageView.setImageBitmap(mImageBitmap);
}

//保存图像
storageDir = new File(Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_PICTURES), getAlbumName()
);
//或者用下面的目录
storageDir = new File (Environment.getExternalStorageDirectory()+ PICTURES_DIR+ getAlbumName()
);private File createImageFile() throws IOException {// Create an image file nameString timeStamp = new SimpleDateFormat("yyyyMMdd_HHmmss").format(new Date());String imageFileName = JPEG_FILE_PREFIX + timeStamp + "_";File image = File.createTempFile(imageFileName, JPEG_FILE_SUFFIX, getAlbumDir());mCurrentPhotoPath = image.getAbsolutePath();return image;
}

如果要向INTENT存放图片数据,用:

File f = createImageFile();
takePictureIntent.putExtra(MediaStore.EXTRA_OUTPUT, Uri.fromFile(f));

The following example method demonstrates how to invoke the system's media scanner to add your photo to the Media Provider's database, making it available in the Android Gallery application and to other apps.

private void galleryAddPic() {Intent mediaScanIntent = new Intent(Intent.ACTION_MEDIA_SCANNER_SCAN_FILE);File f = new File(mCurrentPhotoPath);Uri contentUri = Uri.fromFile(f);mediaScanIntent.setData(contentUri);this.sendBroadcast(mediaScanIntent);
}

下面展示了如何实现缩略图功能(可减少内存使用):

private void setPic() {// Get the dimensions of the Viewint targetW = mImageView.getWidth();int targetH = mImageView.getHeight();// Get the dimensions of the bitmapBitmapFactory.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 imageint scaleFactor = Math.min(photoW/targetW, photoH/targetH);// Decode the image file into a Bitmap sized to fill the ViewbmOptions.inJustDecodeBounds = false;bmOptions.inSampleSize = scaleFactor;bmOptions.inPurgeable = true;Bitmap bitmap = BitmapFactory.decodeFile(mCurrentPhotoPath, bmOptions);mImageView.setImageBitmap(bitmap);
}

官方接下来的内容还展示了如何获取录下的视频以及相机的控制,请自行查看。


官方还提供了一些基础的组件让你显示图片还有HTML:

https://developer.android.com/training/printing/index.html

转载于:https://www.cnblogs.com/yutoulck/p/3407412.html

Training—Capturing Photos相关推荐

  1. Android官方文档training中英文翻译目录大全:29篇已翻译,45篇未翻译

    Android官方文档training中英文翻译目录大全:29篇已翻译,45篇未翻译 1. Getting Started Building Your First App: 原文: https://d ...

  2. 一款不错的开源屏幕(窗口)录制软件 CamStudio

    参考网址 : http://www.funchords.com/ In my Favorite Freeware aisle, I'm sharing those programs that: I u ...

  3. Android 打印,搜索连接同一局域网下的所有网络打印机,打印照片,打印自定义文档。

    Android 搜索局域网下的所有网络打印机,打印照片,打印自定义文档. Android 连接局域网下的网络打印机打印图片,和自定义文档打印 github地址: https://github.com/ ...

  4. iPhone摄影中的深度捕捉(WWDC2017-Session 507)

    视频地址,只能用safari观看 前言 507是深度媒体相关的概念层面的内容.主要为下面4个部分: Depth and disparity on iPhone 7 Plus Streaming dep ...

  5. 计算机文档xsl,XSL文件扩展名 - 什么是.xsl以及如何打开? - ReviverSoft

    你在这里因为你有,有一个文件扩展名结尾的​​文件 .xsl. 文件与文件扩展名 .xsl 只能通过特定的应用程序推出.这有可能是 .xsl 文件是数据文件,而不是文件或媒体,这意味着他们并不是在所有观 ...

  6. iphone 相机拍摄比例_如何在iPhone上拍摄RAW照片

    iphone 相机拍摄比例 RAW is an image format that contains a lot more data than JPG. It's designed so that y ...

  7. CNN 图像增强--DSLR-Quality Photos on Mobile Devices with Deep Convolutional Networks

    DSLR-Quality Photos on Mobile Devices with Deep Convolutional Networks ICCV2017 http://people.ee.eth ...

  8. Android官方开发文档Training系列课程中文版:后台服务之响应IntentService的处理结果

    原文地址:https://developer.android.com/training/run-background-service/report-status.html 这节课主要学习如何将Inte ...

  9. 【训练过程】1) Create Training File(创建训练文件)

    1) Create Training File(创建训练文件) Put the folders of VOC dataset(clean images是原始的干净图像(VOC)), collected ...

最新文章

  1. 转:delphi异常捕获try except语句 和 try finally语句用法
  2. Spring学习笔记之一----基于XML的Spring IOC配置
  3. hdu1716 排列2(排列生成算法)
  4. tf.nn.embedding_lookup函数的用法
  5. vue 分模块打包 脚手架_手动撸一个webpack4脚手架(仿vuecli2)
  6. android里面画布快照,自定义 View - Canvas - 画布操作和快照
  7. linux下vi常用命令——读《鸟哥的linux私房菜》整理
  8. vs需要迁移_【迁移指南】从Web开发者到Flutter开发者
  9. python 网络爬虫 第一天
  10. ERP系统健康体检的三大指标
  11. 五脏六腑在脸上的反射区图片_“阳光运动场,亲子共成长”——赣县区白鹭乡中心幼儿园迎新年亲子趣味运动会...
  12. Spring 之bean的注入
  13. eclipse的安装与环境配置
  14. java 计算同比增长工具类
  15. 什么叫弹性计算云服务器,弹性云服务器
  16. 阿里p6和p7的主要区别是什么?
  17. Arcgis地图切片专题(关于tpk的制作以及迁移切片包至服务器的相关流程)
  18. Vue 运行提示“没有注册类”的解决办法
  19. 大家都在用哪些OKR管理工具?
  20. 一期Go群问答-并发控制-数据竞争-错误与异常

热门文章

  1. php extension 安装,php + clucene extension的安装
  2. linux培训描述,【linux培训班】关于linux系统记录和描述进程的分析
  3. java垃圾回收机制串行_Java垃圾回收机制
  4. kubernetes不同的命名空间下的容器能通信吗_超长干货 | Kubernetes命名空间详解
  5. 047_Object对象
  6. 084_html5WebWorkers
  7. qt qtableview 刷新列表_qt qtablewidget 刷新
  8. JavaWeb:JavaScript
  9. c++ string 堆还是栈_5个刁钻的String面试题解析
  10. hao123电脑版主页_生活小技巧003:电脑主页被恶意篡改怎么办?