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 参考. ...
随机推荐
- 启动Windows PowerShell ISE
Windows Server 2008 R2 环境下,启动PoserShell ISE方法: 方法1:在cmd.exe控制台或运行框中,输入 powershell_ise.exe 执行即可. 方法2: ...
- HashMap和List遍历方法总结及如何遍历删除元素
https://blog.csdn.net/demohui/article/details/77748809
- R in action读书笔记(14)第十一章 中级绘图 之一:散点图(高能预警)
第十一章中级绘图 本章内容: 二元变量和多元变量关系的可视化 绘制散点图和折线图 理解相关图 学习马赛克图和关联图 本章用到的函数有: plot hexbin ablines iplot scatte ...
- Python学习 Day 8 继承 多态 Type isinstance dir __slots__
继承和多态 在OOP程序设计中,当我们定义一个class的时候,可以从某个现有的class继承,新的class称为子类(Subclass),而被继承的class称为基类.父类或超类(Base clas ...
- Codeforces_791_B. Bear and Friendship Condition_(dfs)
B. Bear and Friendship Condition time limit per test 1 second memory limit per test 256 megabytes in ...
- Java入门第38课——猜字母游戏之设计程序结构
问题 本案例需要实现猜字母游戏程序中的程序结构 方案 分析猜字母游戏可以看出,程序首先需要随机产生5个不同的字母作为需要猜测的结果,因此,可以先定义一个方法,以实现此功能: ...
- GIT 获取指定历史版本代码
cd 到该项目的一个本地仓库下 log 查看提交记录,找到想要的提交记录,粘贴对应的希哈值 执行 git checkout 希哈值 这本地的这个仓库的代码就会变成你想要的那个版本的代码
- jQuery动态移除和绑定事件
function bindEvent() { //移除绑定事件 $('.btnsp').unbind('click'); //绑定事件 $('.btnsp').bind('click', functi ...
- linux中查看文件指定行的数据
http://jingyan.baidu.com/article/15622f24125872fdfdbea560.html
- jquery.guide.js 新手指引
/*! * by xyb * 新版上线时候的黑色半透明镂空遮罩指引效果实现jQuery小插件 * 兼容到IE8+ * MIT使用协议,使用时候保留版权 * */ $.guide = function ...