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中的更多相关文章

  1. 黎活明8天快速掌握android视频教程--14_把文件存放在SDCard

    把文件保存在手机的内部存储空间中 1 首先必须在清单文件中添加权限 <?xml version="1.0" encoding="utf-8"?> & ...

  2. WPFMediaKit照相功能

    最近写的一个WPF照相功能,往各位吐槽,提供优化 在WPF 设计器中添加如下代码 xmlns:wpfmedia="clr-namespace:WPFMediaKit.DirectShow.C ...

  3. Android简单调用相机Camera功能,实现打开照相功能

    在最開始接触Android相机功能之前,先来体验一下Android调用系统照相功能吧 核心代码 Intent intent = new Intent(); //调用照相机 intent.setActi ...

  4. Java实现购物车功能:方式一:存放在session中.方式二:存储在数据库中

    //将购物车产品加入到cookie中,方式同浏览记录.Java实现购物车,方式一(简易版):存储在session中.这种方式实现还不严谨,大家看的时候看思路即可.(1). JSP页面中,选择某一款产品 ...

  5. android: 从相册中选择照片

    虽然调用摄像头拍照既方便又快捷,但并不是每一次我们都需要去当场拍一张照片的. 因为每个人的手机相册里应该都会存有许许多多张照片,直接从相册里选取一张现有的照 片会比打开相机拍一张照片更加常用.一个优秀 ...

  6. Git项目存放位置在导入Eclipse前不能存放在Eclipse Workspace

    这篇帖子的背景: 本人想将一个git项目导入至Eclipse的Workspace中,并且该项目的所有git信息.但是,该git项目在导入之前,就已经存放在Eclipse的Workspace中.在将该g ...

  7. Android 8.0 功能和 API

    Android 8.0 为用户和开发者引入多种新功能.本文重点介绍面向开发者的新功能. 用户体验 通知 在 Android 8.0 中,我们已重新设计通知,以便为管理通知行为和设置提供更轻松和更统一的 ...

  8. 集成Android免费语音合成功能(在线、离线、离在线融合)

    集成Android免费语音合成功能(在线.离线.离在线融合),有这一篇文章就够了(离线)集成Android免费语音合成功能(在线.离线.离在线融合),有这一篇文章就够了(离在线融合) 转眼间,大半年没 ...

  9. Android 9 新功能 及 API 介绍(提供了实用的模块化的功能支持,包括 人工智能)

      Android 9(API 级别 28)为用户和开发者引入了众多新特性和新功能. 本文重点介绍面向开发者的新功能. 要了解新 API,请阅读 API 差异报告或访问 Android API 参考. ...

随机推荐

  1. ambari集群里如何正确删除历史修改记录(图文详解)

    不多说,直接上干货! 答:这些你想删除的话得得去数据库里删除,最好别删除 .  现在默认就是使用好的配置               欢迎大家,加入我的微信公众号:大数据躺过的坑        人工智 ...

  2. redis 远程连接方法

    解决方法 1.修改redis服务器的配置文件 vi redis.conf 注释以下绑定的主机地址 # bind 127.0.0.1 或 vim  redis.conf bind  0.0.0.0 pr ...

  3. Asp.Net中调用存储过程并返回输出参数

    /// <summary> /// 调用存储过程返回参数 /// </summary> /// <param name="orderId">&l ...

  4. [翻译] API测试最佳实践 - 组织你的测试

    组织你的测试 适用级别:初学者 在最底层,一个测试步骤(Test Step)用来验证一个单独的操作.组合若干测试步骤到测试用例,允许你验证那些被分隔出来的一个一个的功能,这些功能是应用程序所需要的.接 ...

  5. iOS :Object-C 语言merge两个字典对象

    Object-C 语言merge两个字典对象 - (id)mutableDictionaryCopyIfNeeded:(id)dictObj { if ([dictObj isKindOfClass: ...

  6. RDO、SAD、SATD、λ相关概念【转】

    率失真优化概述: 率失真优化(Rate D isto r t i on Op t i m ized)策略是在率失真理论[3 ]的基础上提出的一种代价函数方案, RDO 的主要思想是, 在计算代价函数时 ...

  7. sql server查看某个表上的触发器

    用企业管理器查看 在某个具体的表上点右键->“所有任务”->“管理触发器”,选择所要查看的触发器

  8. Node.js——body方式提交数据

    引入核心模块 http,利用其 api(http.createServer) 返回一个 http.server 实例,这个实例是继承于net.Server,net.Server 也是通过net.cre ...

  9. vue热重载

    依据官网使用 webpack 的 Hot Module Replacement API,Vuex 支持在开发过程中热重载 mutation.module.action 和 getter.你也可以在 B ...

  10. @import与link方式的区别

    1. 老祖宗的差别.link属于XHTML标签,而@import完全是CSS提供的一种方式. link标签除了可以加载CSS外,还可以做很多其它的事情,比如定义RSS,定义rel连接属性等,@impo ...