- 浏览: 249300 次
- 性别:
- 来自: 济南
文章分类
- 全部博客 (303)
- c (31)
- c++ (16)
- java (18)
- c# (1)
- python (3)
- java web (6)
- oracle (7)
- sqlserver (2)
- mysql (2)
- android (24)
- android系统 (15)
- android多媒体部分 (15)
- android游戏 (12)
- linux (26)
- javaScript (1)
- ajax (1)
- node JS (2)
- html (5)
- apache (3)
- jboss (1)
- weblogic (0)
- 通信协议 (10)
- 云计算 (1)
- 分布式 (5)
- ejb (1)
- webservice (5)
- 设计模式 (16)
- JNI (6)
- swing (13)
- 版本控制 (1)
- UML (1)
- xml (4)
- spring (5)
- hibernate (5)
- struts1 (3)
- struts2 (4)
- ibatis (0)
- tomcat (2)
- 心得体会 (1)
- css (1)
- 嵌入式 (41)
- arm体系结构 (10)
1 使用内置的camera应用程序捕获图像
/**
* 拍摄一张照片保存到sd卡上
*/
private void takeAndSaveImage() {
// 取得路径
imageFilePath = Environment.getExternalStorageDirectory().getAbsolutePath() + "/myfavoritepicture.jpg";
Log.i("tag", "sd card path:" + 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);
}
/**
* 显示一张相片
*/
private void displayImage() {
// 取得屏幕大小
Display display = getWindowManager().getDefaultDisplay();
int dw = display.getWidth();
int dh = display.getHeight();
Log.i("tag", "dw:" + dw + " dh:" + dh);
// 加载图像的尺寸而不是图像本身
bmpOptions = new BitmapFactory.Options();
// 如果为true,只须返回图像的范围,不须尝试解码图像本身
bmpOptions.inJustDecodeBounds = true;
// options.inSampleSize = 8;
Bitmap bitmap = BitmapFactory.decodeFile(imageFilePath, bmpOptions);
int hRatio = (int) Math.ceil(bmpOptions.outHeight / (float) dh);
int wRatio = (int) Math.ceil(bmpOptions.outWidth / (float) dw);
Log.i("tag", "hRatio" + hRatio);
Log.i("tag", "wRatio" + wRatio);
// 如果两个比率都大于1
// 那么图像的一条边将大小屏幕
if (hRatio > 1 && wRatio > 1) {
if (hRatio > wRatio) {
Log.i("tag", "hRatio" + hRatio);
// 若高度比率更大,则根据它缩放
bmpOptions.inSampleSize = hRatio;
} else {
Log.i("tag", "wRatio" + wRatio);
// 反之则根据宽度缩放
bmpOptions.inSampleSize = wRatio;
}
}
// 对图像进行解码
bmpOptions.inJustDecodeBounds = false;
bitmap = BitmapFactory.decodeFile(imageFilePath, bmpOptions);
// 显示图片
imageView.setImageBitmap(bitmap);
}
注:所需权限
<uses-permission android:name="android.permission.CAMERA" />
2 图像存储和元数据
获取图像的uri
使用MediaStore存储图像
/**
* 取得图像的uri
*
* 如果是存储在SD卡上 EXTERNAL_CONTENT_URI 如果是存储在设备内存中 INTERNAL_CONTENT_URI
*/
private void getImageURI() {
// 在contentValues映射中保存图像的名称和描述
ContentValues contentValues = new ContentValues();
contentValues.put(Media.DISPLAY_NAME, "this is a test title");
contentValues.put(Media.DESCRIPTION, "this is a test description");
contentValues.put(Media.MIME_TYPE, "image/jpeg");
imageFileUri = getContentResolver().insert(Media.EXTERNAL_CONTENT_URI, contentValues);
// 方法二:后期添加元数据
// ContentValues contentValues = new ContentValues();
// contentValues.put(Media.DISPLAY_NAME, "this is a test title");
// contentValues.put(Media.DESCRIPTION, "this is a test description");
// contentValues.put(Media.MIME_TYPE, "image/jpeg");
// getContentResolver().update(imageFileUri, contentValues, null, null);
Intent intent = new Intent(android.provider.MediaStore.ACTION_IMAGE_CAPTURE);
intent.putExtra(android.provider.MediaStore.EXTRA_OUTPUT, imageFileUri);
startActivity(intent);
}
使用MediaStore检索图像章
/**
* 检索保存的图像
*
* @throws FileNotFoundException
*/
private void findBitmap() throws FileNotFoundException {
BitmapFactory.decodeStream(getContentResolver().openInputStream(imageFileUri), null, bmpOptions);
}
发表评论
-
android多媒体学习笔记二
2012-09-04 10:53 778实现SurfaceHolder.Callback ,P ... -
android多媒体学习笔记三___图像合成
2012-09-05 11:36 593/** * 图像合成 * * @time 下午06:21 ... -
android多媒体部分学习笔记四___ Matrix
2012-09-05 11:40 687/*** 图像的缩放和旋转 Matrix** 1 0 0 x= ... -
android多媒体部分学习笔记五----audio
2012-09-08 16:08 681/*** 打开内置音乐播放器*/private void ge ... -
android多媒体部分学习笔记六----音频录制 mediaRecorder
2012-09-08 16:12 635/** * * 使用意图捕获音频 * * @time ... -
android多媒体部分学习笔记七------音频录制 mediaRecorder
2012-09-08 16:13 717/** * 自定义捕获音频 * * @time 下午12 ... -
android多媒体部分学习笔记八------音频录制 mediaRecorder
2012-09-08 16:14 732/** * 原始音频的播放和录制 * * audio ... -
android 多媒体部分学习笔记九----数字音频合成
2012-09-09 12:43 802/** * 数字音频合成 * * @time 下午12: ... -
android 多媒体部分学习笔记十 可视化频率(频谱)
2012-09-09 23:43 3180/** * 可视化频率 * * @time 下午12 ... -
android 多媒体部分学习笔记十--简单视频播放
2012-09-10 17:53 724/** * 简单播放 * * @time 下午05:15 ... -
android 多媒体部分学习笔记十二----mediaplay自定义播放器
2012-09-10 22:31 1605/** * * 自定义播放器 * * @time 下午 ... -
android 多媒体部分学习笔记十三----mediaStore 检索视频
2012-09-12 00:12 981/** * mediaStore检索视频 * * @ti ... -
android 多媒体部分学习十四---网络视频播放(http/rtsp)
2012-09-12 14:36 1813/** * 网络视频播放 * * openCore * ... -
android 多媒体部分学习笔记十五-----视频录制
2012-09-12 15:02 715/** * 调用系统视频录制 * * @time 下午0 ...
相关推荐
Android 开发学习笔记,学习android的好资料
Android学习笔记 Android学习笔记 Android学习笔记
第一行代码 android学习笔记 修改完整版
Android学习笔记
Android开发学习笔记(整理),整理论坛android学习笔记,较完整的讲解了android的内容。包括:view、activity、service、intent、广播机制、http连接、数据sqllite存储、后台线程、各种layout、偏好、本地文件操作、...
Android学习笔记(一)——创建第一个Android项目 Android学习笔记(二)android studio基本控件及布局(实现图片查看器) Android学习笔记(三)android studio中CheckBox自定义样式(更换复选框左侧的勾选图像) ...
Android基础学习笔记,自己总结,适合初学者。
android入门学习笔记
Android_学习笔记 Android_学习笔记 Android_学习笔记
android 学习笔记(全全整理),吧android学习笔记全部整理下来了,可以去好好学习学习
这是一个用android studio开发的小demo,只有一个TextView和一个Button,button实现了点击事件
Android Animation学习笔记
学习java和android的笔记 更容易学习android 资深学习android 具有大量学习的笔记 很多的错误 都是从细节开始学习的
android 学习笔记 android 学习笔记 android 学习笔记
Android+学习笔记,很实在的东西,没一句废话,第一手的学习笔记
android JNI 学习笔记 android JNI 学习笔记.doc
Android_学习笔记
Android Intent 学习笔记
android service 学习笔记(上、下)android service 学习笔记(上、下)