方法一:

此方法会由Camera直接产生照片回传给应用程序,但是返回的是压缩图片,显示不清晰

1
2
3
4
5
6
try
{
     Intent cameraIntent =
new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
     startActivityForResult(cameraIntent, CAMERA_WITH_DATA);
 }
catch (ActivityNotFoundException e) {
     e.printStackTrace();
 }
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
Bundle bundle = data.getExtras();
bmp_selectedPhoto = (Bitmap) bundle.get("data");
if
(bmp_selectedPhoto !=
null)
    bmp_selectedPhoto.recycle();
bmp_selectedPhoto = (Bitmap) data.getExtras().get("data");
// int scale = ImageThumbnail.reckonThumbnail(bitMap.getWidth(),
// bitMap.getHeight(), 500, 600);
// bitMap = ImageThumbnail.PicZoom(bitMap,
// (int) (bitMap.getWidth() / scale),
// (int) (bitMap.getHeight() / scale));
// bitMap = ThumbnailUtils.extractThumbnail(bitMap, 200, 200);
if(bmp_selectedPhoto !=
null){
    home_view.setBackground(new
BitmapDrawable(getResources(),
    bmp_selectedPhoto));
}

方法二:

此方法所拍即所得,但是会在Sd卡上产生临时文件

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
Intent cameraIntent =
new Intent(
                android.provider.MediaStore.ACTION_IMAGE_CAPTURE);
 
        File appDir =
new File(Environment.getExternalStorageDirectory()
                +
"/KengDieA");
         
        if
(!appDir.exists()) {
            appDir.mkdir();
        }
 
        mUri = Uri.fromFile(new
File(Environment.getExternalStorageDirectory()
                +
"/KengDieA/",
"kengDiePic"
                + String.valueOf(System.currentTimeMillis()) +
".jpg"));
        cameraIntent.putExtra(android.provider.MediaStore.EXTRA_OUTPUT, mUri);
 
        try
{
            cameraIntent.putExtra("return-data",
true);
            startActivityForResult(cameraIntent, CAMERA_WITH_DATA);
        }
catch (Exception e) {
            e.printStackTrace();
        }
1
2
3
4
5
6
7
8
9
10
11
12
ContentResolver cr =
this.getContentResolver();
            try
{
                if
(bmp_selectedPhoto != null)// 如果不释放的话,不断取图片,将会内存不够
                    bmp_selectedPhoto.recycle();
                bmp_selectedPhoto = BitmapFactory.decodeStream(cr
                        .openInputStream(mUri));
            }
catch (FileNotFoundException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            }
            home_view.setBackground(new
BitmapDrawable(getResources(),
                    bmp_selectedPhoto));

Android从Camera中获取图片的两种方法的更多相关文章

  1. php获取数组中重复数据的两种方法

    分享下php获取数组中重复数据的两种方法. 1,利用php提供的函数,array_unique和array_diff_assoc来实现 <?php function FetchRepeatMem ...

  2. python中执行shell的两种方法总结

    这篇文章主要介绍了python中执行shell的两种方法,有两种方法可以在Python中执行SHELL程序,方法一是使用Python的commands包,方法二则是使用subprocess包,这两个包 ...

  3. vue中使用echarts的两种方法

    在vue中使用echarts有两种方法一.第一种方法1.通过npm获取echarts npm install echarts --save 2.在vue项目中引入echarts 在 main.js 中 ...

  4. PHP中获取星期的几种方法

    PHP中获取星期的几种方法   PHP星期几获取代码: 1 date(l); 2 //data就可以获取英文的星期比如Sunday 3 date(w); 4 //这个可以获取数字星期比如123,注意0 ...

  5. [转]Qt中定时器使用的两种方法

    Qt中定时器的使用有两种方法,一种是使用QObject类提供的定时器,还有一种就是使用QTimer类. 其精确度一般依赖于操作系统和硬件,但一般支持20ms.下面将分别介绍两种方法来使用定时器. 方法 ...

  6. AE 将地图导出为图片的两种方法

    在ArcGIS的开发中,我们经常需要将当前地图打印(或是转出)到图片文件中.将Map或Layout中的图象转出有两种方法,一种为通过IActiveView的OutPut函数,另外一种是通过IExpor ...

  7. UIImage加载图片的两种方法区别

    Apple官方的文档为生成一个UIImage对象提供了两种方法加载图片: 1. imageNamed,其参数为图片的名字: 2. imageWithContentsOfFile,其参数也是图片文件的路 ...

  8. Ajax中解析Json的两种方法详解

    eval();  //此方法不推荐 JSON.parse();  //推荐方法 一.两种方法的区别 我们先初始化一个json格式的对象: var jsonDate = '{ "name&qu ...

  9. input上传图片(file),预览图片的两种方法。blob与base64编码

    上传图片时一般都需要预览,我一般用这两种方法来实现.base64编码可以直接上传到后台,后台解析下,得到的文件就会比较小了,省去了压缩图片这一步了. //获取对象input file 的图片地址,放进 ...

随机推荐

  1. 关于python字典中文显示的处理办法

    最近工作中遇到字典包含中文,显示\uxxxx的问题,怎么转换都无法输入正常的中文:{"gc": "\u4eba\u751f\u7f8e\u597d", &quo ...

  2. 嵌入式LinuxC语言程序设计基础教程

    第1章 嵌入式LinxuC语言开发工具 第2章 数据 第3章 数据的输入输出 第4章 运算符和表达式 第5章 程序结构和控制语句 第6章 数组 第7章 指针 第8章 函数 第9章 用户自定义数据类型 ...

  3. 洛谷 1091 合唱队形(NOIp2004提高组)

    [题解] 分别做一遍最长上升序列和最长下降序列,再枚举峰的位置计算答案即可. #include<cstdio> #include<algorithm> #include< ...

  4. saltstack(四) saltstack的targeting、分组

    targeting支持如下matcher: Globing : '*', 正则: 指定-E参数,正则表达式匹配多个 List: 指定-L参数,salt -E 'web1-(prod|devel)' t ...

  5. selectByExampleWithBLOBs-----搜索结果包含大字段类型----搜索结果包含大字段类型

    http://www.jb51.net/article/121482.htm mybatis generator 使用方法教程(生成带注释的实体类)

  6. BNUOJ 2461 Anniversary party

    Anniversary party Time Limit: 1000ms Memory Limit: 65536KB This problem will be judged on PKU. Origi ...

  7. UVA 12686 Trending Topic

    Trending Topic Time limit: 1.000 seconds Imagine you are in the hiring process for a company whose p ...

  8. [luoguP2486] [SDOI2011]染色(树链剖分)

    传送门 就是个模板啦 记录每一个点的左端点颜色和右端点颜色和当前端点颜色段数. 合并时如果左孩子右端点和右孩子左端点不同就 ans-- 在重链上跳的时候别忘记统计一下 ——代码 #include &l ...

  9. 定义Portal显示规则

    Defining Portal Display Rules Use You use the Portal Display Rules editor to create and edit rule co ...

  10. 矩阵覆盖,基本DP题目

    https://www.nowcoder.net/practice/72a5a919508a4251859fb2cfb987a0e6?tpId=13&tqId=11163&tPage= ...