android 实现照相功能 照片存放在SID卡中,将照片显示在Image中
protected static final int CAMERA_RESULT = 0;
private String fileName;
private Button takePhotoBn;
private String imageFilePath; private ImageView imv;
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent intent)
{
// TODO Auto-generated method stub
super.onActivityResult(requestCode, resultCode, intent);
// 如果拍照成功
if (resultCode == RESULT_OK)
{ // Bundle extras = intent.getExtras();
// Bitmap bmp = (Bitmap)extras.get("data");
imv = (ImageView) findViewById(R.id.imageView1);
// 取得屏幕的显示大小
Display currentDisplay = getWindowManager().getDefaultDisplay();
int dw = currentDisplay.getWidth();
int dh = currentDisplay.getHeight();
// 对拍出的照片进行缩放
BitmapFactory.Options bmpFactoryOptions = new BitmapFactory.Options();
bmpFactoryOptions.inJustDecodeBounds = true;
Bitmap bmp = BitmapFactory.decodeFile(imageFilePath, bmpFactoryOptions);
int heightRatio = (int) Math.ceil(bmpFactoryOptions.outHeight / (float) dh);
int widthRatio = (int) Math.ceil(bmpFactoryOptions.outWidth / (float) dw);
if (heightRatio > 1 && widthRatio > 1)
{ if (heightRatio > widthRatio)
{
bmpFactoryOptions.inSampleSize = heightRatio;
} else
{
bmpFactoryOptions.inSampleSize = widthRatio;
} }
bmpFactoryOptions.inJustDecodeBounds = false;
bmp = BitmapFactory.decodeFile(imageFilePath, bmpFactoryOptions);
try
{
MediaStore.Images.Media.insertImage(getContentResolver(),
imageFilePath, fileName, null);
} catch (FileNotFoundException e)
{
// TODO Auto-generated catch block
e.printStackTrace();
}
imv.setImageBitmap(bmp);
}
} @Override
protected void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
ImageView mImageView = (ImageView) findViewById(R.id.image);
takePhotoBn = (Button) findViewById(R.id.button1);
imv = (ImageView) findViewById(R.id.imageView1);
// 点击Photo Button按钮照相
takePhotoBn.setOnClickListener(new OnClickListener()
{
@Override
public void onClick(View v)
{
fileName = System.currentTimeMillis() + ".jpg";
File appDir = new File(Environment.getExternalStorageDirectory(), "ImageFile");
if (!appDir.exists()) {
appDir.mkdir();
}
imageFilePath = Environment.getExternalStorageDirectory().getAbsolutePath() + "/ImageFile/"+fileName;
System.out.println("====imageFilePath===="+imageFilePath);
File imageFile = new File(imageFilePath);
Uri imageFileUri = Uri.fromFile(imageFile);
Intent i = new Intent(android.provider.MediaStore.ACTION_IMAGE_CAPTURE);
i.putExtra(android.provider.MediaStore.EXTRA_OUTPUT, imageFileUri);
startActivityForResult(i, CAMERA_RESULT); }
}); }
android 实现照相功能 照片存放在SID卡中,将照片显示在Image中的更多相关文章
- 黎活明8天快速掌握android视频教程--14_把文件存放在SDCard
把文件保存在手机的内部存储空间中 1 首先必须在清单文件中添加权限 <?xml version="1.0" encoding="utf-8"?> & ...
- WPFMediaKit照相功能
最近写的一个WPF照相功能,往各位吐槽,提供优化 在WPF 设计器中添加如下代码 xmlns:wpfmedia="clr-namespace:WPFMediaKit.DirectShow.C ...
- Android简单调用相机Camera功能,实现打开照相功能
在最開始接触Android相机功能之前,先来体验一下Android调用系统照相功能吧 核心代码 Intent intent = new Intent(); //调用照相机 intent.setActi ...
- Java实现购物车功能:方式一:存放在session中.方式二:存储在数据库中
//将购物车产品加入到cookie中,方式同浏览记录.Java实现购物车,方式一(简易版):存储在session中.这种方式实现还不严谨,大家看的时候看思路即可.(1). JSP页面中,选择某一款产品 ...
- android: 从相册中选择照片
虽然调用摄像头拍照既方便又快捷,但并不是每一次我们都需要去当场拍一张照片的. 因为每个人的手机相册里应该都会存有许许多多张照片,直接从相册里选取一张现有的照 片会比打开相机拍一张照片更加常用.一个优秀 ...
- Git项目存放位置在导入Eclipse前不能存放在Eclipse Workspace
这篇帖子的背景: 本人想将一个git项目导入至Eclipse的Workspace中,并且该项目的所有git信息.但是,该git项目在导入之前,就已经存放在Eclipse的Workspace中.在将该g ...
- Android 8.0 功能和 API
Android 8.0 为用户和开发者引入多种新功能.本文重点介绍面向开发者的新功能. 用户体验 通知 在 Android 8.0 中,我们已重新设计通知,以便为管理通知行为和设置提供更轻松和更统一的 ...
- 集成Android免费语音合成功能(在线、离线、离在线融合)
集成Android免费语音合成功能(在线.离线.离在线融合),有这一篇文章就够了(离线)集成Android免费语音合成功能(在线.离线.离在线融合),有这一篇文章就够了(离在线融合) 转眼间,大半年没 ...
- Android 9 新功能 及 API 介绍(提供了实用的模块化的功能支持,包括 人工智能)
Android 9(API 级别 28)为用户和开发者引入了众多新特性和新功能. 本文重点介绍面向开发者的新功能. 要了解新 API,请阅读 API 差异报告或访问 Android API 参考. ...
随机推荐
- 171 Excel Sheet Column Number Excel表列序号 26进制转10进制
给定一个Excel表格中的列名称,返回其相应的列序号.示例: A -> 1 B -> 2 C -> 3 ... Z -> 26 AA -&g ...
- Oracle对表空间无权限
有的时候我们在Oracle数据库中对执行insert.update之类的语句时会出错,Oracle说我们对表空间无权限.执行下面的语句就可以修改用户对表空间的权限了. 执行语句: alter user ...
- .net主站和二级域名下实现session共享
public class CrossDomainCookie : IHttpModule { private string m_RootDomain = string.Empty; #region I ...
- java课程设计全程实录——第1天
反思,总结昨天: IDE搭建完成: git远程配置失败,处理方式:放弃使用git 主要参考<疯狂java实战演义>中的图书进销存管理系统.但该项目是MySQL,无法直接套用,因为我们学的是 ...
- php debug/phpstorm调试
apache+phpstorm调试php代码,修改php.ini配置文件开启调试,没有以下代码加上即可, [XDebug]zend_extension="C:\php\php-7.0.12- ...
- react学习文档
转自http://www.ruanyifeng.com/blog/2015/03/react.html,阮一峰老师的博客. 最近想学习react,官方文档的例子不是那么浅显易懂,看了相关博客,觉得阮一 ...
- Django model 反向引用中的related_name
转自:https://blog.csdn.net/lanyang123456/article/details/68962515 问题: 定义表Apple: class Apple( models.Mo ...
- ListView相关知识点
最近开发接触到了ListView控件,其实简单的需求基本上源生的都可以满足,下面总结一下开发过程中所遇到的关键点: 1.多级ListView联动,保存位置:即切换第一层ListView的item过程中 ...
- redis 可视化管理工具
Redis Desktop Manager 下载地址:http://redisdesktop.com/download 支持: Windows 7+, Mac OS X 10.10+, Ubuntu ...
- iis 配置文件解决跨域问题
<system.webServer> <httpProtocol> <customHeaders> <add name="Access-Contro ...