Android Camera
Android调用系统api使用照相机功能,实现拍照获取图片以及从照相机库中获取指定图片的功能。
下面是演示样例代码:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/main"
android:layout_width="match_parent"
android:layout_height="match_parent" >
<ImageView android:layout_width="match_parent"
android:layout_height="100dip"
android:id="@+id/image"
/>
<Button
android:id="@+id/btn"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="testPopupWindow"
android:layout_below="@id/image"
/> </RelativeLayout>
/**
* 实现Popup弹出窗体并实现调用系统照相机功能
* @author dream
*
*/
public class TestPopupWindow extends Activity {
private SelectPopupWindow popupWindow;
private ImageView image;
private Button btn;
private Uri fileUri; @Override
protected void onCreate(Bundle savedInstanceState) {
// TODO Auto-generated method stub
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main1);
init();
} private void init(){
image = (ImageView) findViewById(R.id.image);
btn = (Button) findViewById(R.id.btn);
btn.setOnClickListener(onClickListener);
fileUri = Uri.fromFile(new File(Environment.getExternalStorageDirectory(), "temp.jpg")); //图片存放路径
} View.OnClickListener onClickListener = new View.OnClickListener() { @Override
public void onClick(View v) {
switch(v.getId()){
case R.id.btn:
test();
break;
case R.id.takephoto:
Intent intent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
intent.putExtra(MediaStore.EXTRA_OUTPUT, fileUri);
startActivityForResult(intent, 100);
break;
case R.id.selectfromalbum:
Intent intent1 = new Intent(Intent.ACTION_PICK);
intent1.setDataAndType(MediaStore.Images.Media.EXTERNAL_CONTENT_URI, "image/*");
startActivityForResult(intent1, 200);
break; }
}
}; @Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
// TODO Auto-generated method stub
super.onActivityResult(requestCode, resultCode, data);
if(requestCode == 100 && resultCode == RESULT_OK){
int width = image.getWidth();
int height = image.getHeight();
BitmapFactory.Options opts = new BitmapFactory.Options();
opts.inJustDecodeBounds = true;
BitmapFactory.decodeFile(fileUri.getPath(), opts);
int w = opts.outWidth;
int h = opts.outHeight;
int factor;
if(w>width && h>height){
factor = Math.min(w/width, h/height); //依据ImageView的大小按一定比例缩小图片
}else {
factor = 1;
}
opts.inSampleSize = factor;
opts.inJustDecodeBounds = false;
Bitmap bm = BitmapFactory.decodeFile(fileUri.getPath(), opts);
image.setImageBitmap(bm);
} else if(requestCode == 200 && resultCode == RESULT_OK){
int width = image.getWidth();
int height = image.getHeight();
BitmapFactory.Options opts = new BitmapFactory.Options();
opts.inJustDecodeBounds = true;
Uri uri = data.getData();
try {
InputStream in = getContentResolver().openInputStream(uri);
BitmapFactory.decodeStream(in, null, opts);
int w = opts.outWidth;
int h = opts.outHeight;
int factor;
if(w>width && h>height){
factor = Math.min(w/width, h/height); //依据ImageView的大小按一定比例缩小图片
}else {
factor = 1;
}
opts.inSampleSize = factor;
opts.inJustDecodeBounds = false;
in = getContentResolver().openInputStream(uri); //须要再次获取,由于前面流已经改变了
Bitmap bm = BitmapFactory.decodeStream(in, null, opts);
image.setImageBitmap(bm);
} catch (FileNotFoundException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} } } public void test(){
popupWindow = new SelectPopupWindow(this, onClickListener);
popupWindow.showAtLocation(findViewById(R.id.main),
Gravity.BOTTOM|Gravity.CENTER_HORIZONTAL, 0, 0);
} }
执行结果:
watermark/2/text/aHR0cDovL2Jsb2cuY3Nkbi5uZXQv/font/5a6L5L2T/fontsize/400/fill/I0JBQkFCMA==/dissolve/70/gravity/Center" alt="">
watermark/2/text/aHR0cDovL2Jsb2cuY3Nkbi5uZXQv/font/5a6L5L2T/fontsize/400/fill/I0JBQkFCMA==/dissolve/70/gravity/Center" alt="">
Android Camera的更多相关文章
- 【Android】Android Camera原始帧格式转换 —— 获取Camera图像(一)
概述: 做过Android Camera图像采集和处理的朋友们应该都知道,Android手机相机采集的原始帧(RawFrame)默认是横屏格式的,而官方API有没有提供一个设置Camera采集图像的 ...
- android camera setMeteringArea详解
摘要: 本文为作者原创,未经允许不得转载:原文由作者发表在博客园:http://www.cnblogs.com/panxiaochun/p/5802814.html setMeteringArea() ...
- Android — Camera聚焦流程
原文 http://www.cnphp6.com/archives/65098 主题 Android Camera.java autoFocus()聚焦回调函数 @Override public v ...
- android camera setParameters failed 类问题分析总结
在 monkey test 测试中出现了一例 RuntimeException ,即 setParameters failed. LOG显示为:09-01 18:47:17.348 15656 156 ...
- Android Camera 相机程序编写
Android Camera 相机程序编写 要自己写一个相机应用直接使用相机硬件,首先应用需要一个权限设置,在AndroidManifest.xml中加上使用设备相机的权限: <uses-per ...
- Android Camera 使用小结
Android手机关于Camera的使用,一是拍照,二是摄像,由于Android提供了强大的组件功能,为此对于在Android手机系统上进行Camera的开发,我们可以使用两类方法:一是借助Inten ...
- Android Camera拍照 压缩
http://www.linuxidc.com/Linux/2014-12/110924.htm package com.klp.demo_025; import java.io.ByteArrayI ...
- Android Camera 流程梳理
毕业已经快两年了,一直没有写博客的习惯,这是第一篇,以后要慢慢养成这个习惯.毕业之后一直在做相机,先简单的梳理下Android Camera的流程. Android Camera 是一个client/ ...
- 【转】android camera(四):camera 驱动 GT2005
关键词:android camera CMM 模组 camera参数 GT2005 摄像头常见问题 平台信息: 内核:linux系统:android 平台:S5PV310(samsung exyn ...
- 【转】android camera(三):camera V4L2 FIMC
关键词:android camera CMM 模组 camera参数 CAMIF V4L2 平台信息:内核:linux系统:android 平台:S5PV310(samsung exynos ...
随机推荐
- Android-监听sdcard状态
public class MyService extends Service { private static final String TAG = "MyService"; Fi ...
- Spring的事务传播属性,数据库的隔离级别
Spring事务的传播属性 REQUIRED 业务方法需要在一个事务中运行,如果方法运行时,已处在一个事务中,那么就加入该事务,否则自己创建一个新的事务.这是spring默认的传播行为. SUPPO ...
- bjfu1109 最小公倍数和
这题真是过了n年才a.最早是在2010年北大培训比赛上看到的这题,当时我不会,竹教主也不会,但他记下来了,研究一段时间后就会了,还把这题加到我校oj上.过了这么多年,我上网搜,关于这个问题的解题报告还 ...
- JQuery插件之图片轮播插件–slideBox
来源:http://www.ido321.com/852.html 今天偶然发现了一个比较好用的图片轮播插件—slideBox 先看看效果:http://slidebox.sinaapp.com/ 代 ...
- C#冒泡排序详解
今天写一简单的冒泡排序,带有详细的中文注释,新手一定要看看! 因为这是找工作面试时经常 笔试 要考的题目. using System; using System.Collections.Generic ...
- xcode6默认不支持armv7s
升级到xcode6以后发现,配置里关于Architectures到默认选项只有armv7和arm64.而再次之前xcode5到时代还是有armv7.armv7s和arm64三项的. xcode5.1 ...
- maven系列(2)-第一个maven的项目
上一篇简单了介绍了maven和maven的安装,这篇介绍如何用maven创建项目. 1. 命令行创建maven项目 maven创建项目很简单,直接调用mvn archetype:generate命令即 ...
- Lucene:信息检索与全文检索
目录 信息检索的概念 信息检索技术的分类 全文检索与数据库查询对比 全文检索工具一般由三部分构成 全文检索中建立索引和进行检索的流程 索引里面究竟存什么 如何创建索引 如何对索引进行检索 Lucene ...
- RSA前台js加密,后台C#解密
一.需求: 为了安全,项目中前台登陆用的密码需要加密传到后台,后台c#解密登陆密码. 二.解决方案 采用非对称加密算法RSA来达到目的,前台登陆页面一加载便发送一次ajax请求获取后台产生的公钥,用于 ...
- ALV的报表对用户定义格式的控制(ALV I_SAVE)
很多ALV的报表都需要手动的进行设置格式以使数据看上去更有意义和条理,如果每次进来都重新操作一遍是很烦人的,所以SAP有提供了一个保存格式的功能,保存格式可以是 '缺省设置' 和 '特定用户' 两种 ...