Android大图片裁剪解决方案
来源:互联网 发布:网络运营者应当为 编辑:程序博客网 时间:2024/05/11 22:04
转载声明:Ryan的博客文章欢迎您的转载,但在转载的同时,请注明文章的来源出处,不胜感激! :-)
http://blog.csdn.net/floodingfire/article/details/8144617
上一篇博客中,我们学习到了如何使用Android相册截图。在这篇博客中,我将向大家展示如何拍照截图。
拍照截图有点儿特殊,要知道,现在的Android智能手机的摄像头都是几百万的像素,拍出来的图片都是非常大的。因此,我们不能像对待相册截图一样使用Bitmap小图,无论大图小图都统一使用Uri进行操作。
一、首先准备好需要使用到的Uri:
1
private
static
final
String IMAGE_FILE_LOCATION =
"file:///sdcard/temp.jpg"
;//temp file
2
Uri imageUri = Uri.parse(IMAGE_FILE_LOCATION);
//The Uri to store the big bitmap
二、使用MediaStore.ACTION_IMAGE_CAPTURE可以轻松调用Camera程序进行拍照:
1
Intent intent =
new
Intent(MediaStore.ACTION_IMAGE_CAPTURE);
//action is capture
2
intent.putExtra(MediaStore.EXTRA_OUTPUT, imageUri);
3
startActivityForResult(intent, TAKE_BIG_PICTURE);
//or TAKE_SMALL_PICTURE
01
switch
(requestCode) {
02
case
TAKE_BIG_PICTURE:
03
Log.d(TAG,
"TAKE_BIG_PICTURE: data = "
+ data);
//it seems to be null
04
//TODO sent to crop
05
cropImageUri(imageUri,
800
,
400
, CROP_BIG_PICTURE);
06
07
break
;
08
case
TAKE_SMALL_PICTURE:
09
Log.i(TAG,
"TAKE_SMALL_PICTURE: data = "
+ data);
10
//TODO sent to crop
11
cropImageUri(imageUri,
300
,
150
, CROP_SMALL_PICTURE);
12
13
break
;
14
default
:
15
break
;
16
}
01
private
void
cropImageUri(Uri uri,
int
outputX,
int
outputY,
int
requestCode){
02
Intent intent =
new
Intent(
"com.android.camera.action.CROP"
);
03
intent.setDataAndType(uri,
"image/*"
);
04
intent.putExtra(
"crop"
,
"true"
);
05
intent.putExtra(
"aspectX"
,
2
);
06
intent.putExtra(
"aspectY"
,
1
);
07
intent.putExtra(
"outputX"
, outputX);
08
intent.putExtra(
"outputY"
, outputY);
09
intent.putExtra(
"scale"
,
true
);
10
intent.putExtra(MediaStore.EXTRA_OUTPUT, uri);
11
intent.putExtra(
"return-data"
,
false
);
12
intent.putExtra(
"outputFormat"
, Bitmap.CompressFormat.JPEG.toString());
13
intent.putExtra(
"noFaceDetection"
,
true
);
// no face detection
14
startActivityForResult(intent, requestCode);
15
}
01
switch
(requestCode) {
02
case
CROP_BIG_PICTURE:
//from crop_big_picture
03
Log.d(TAG,
"CROP_BIG_PICTURE: data = "
+ data);
//it seems to be null
04
if
(imageUri !=
null
){
05
Bitmap bitmap = decodeUriAsBitmap(imageUri);
06
imageView.setImageBitmap(bitmap);
07
}
08
break
;
09
case
CROP_SMALL_PICTURE:
10
if
(imageUri !=
null
){
11
Bitmap bitmap = decodeUriAsBitmap(imageUri);
12
imageView.setImageBitmap(bitmap);
13
}
else
{
14
Log.e(TAG,
"CROP_SMALL_PICTURE: data = "
+ data);
15
}
16
break
;
17
default
:
18
break
;
19
}
效果图:
代码托管于GitHub,会不定期更新:https://github.com/ryanhoo/PhotoCropper
0 0
- Android大图片裁剪解决方案
- Android大图片裁剪解决方案
- Android大图片裁剪解决方案
- Android大图片裁剪解决方案
- Android大图片裁剪解决方案
- Android大图片裁剪解决方案
- android Android大图片裁剪终极解决方案
- Android大图片裁剪终极解决方案
- Android大图片裁剪终极解决方案
- Android大图片裁剪终极解决方案
- Android大图片裁剪终极解决方案
- Android大图片裁剪终极解决方案
- Android大图片裁剪终极解决方案
- Android大图片裁剪终极解决方案
- 原理分析 :Android大图片裁剪解决方案
- Android大图片裁剪终极解决方案
- Android大图片裁剪终极解决方案
- Android大图片裁剪终极解决方案
- ThreadPoolExecutor 学习
- 1083. List Grades (25)
- nginx配置详解
- 【LEETCODE】237-Delete Node in a Linked List
- 满秩分解
- Android大图片裁剪解决方案
- Truncate Table 会不会释放索引
- 如何配置outlook邮箱-以Outlook 2013配置QQ邮箱为例
- 遍历propertys
- JQuery - select class 或是select id?
- 事务
- 南大软院大神养成计划——CSS进阶
- JAVA进程间的通信方式(IPC)
- angular js轮播图 (Carousel (ui.bootstrap.carousel))