位置: 编程技术 - 正文
推荐整理分享Android大图片裁剪终极解决方案(中:从相册截图)(android图片裁剪),希望有所帮助,仅作参考,欢迎阅读内容。
文章相关热门搜索词:android图片大小,安卓手机裁图方法,安卓手机图片裁剪为指定大小,android大图片处理,android图片裁剪,android 图片裁剪 任意形状,android图片大小,android图片裁剪,内容如对您有帮助,希望把文章链接给更多的朋友!
转载声明:Ryan的博客文章欢迎您的转载,但在转载的同时,请注明文章的来源出处,不胜感激! :-)
在这篇博客中,我将向大家展示如何从相册截图。
上一篇博客中,我就拍照截图这一需求进行了详细的分析,试图让大家了解Android本身的限制,以及我们应当采取的实现方案。
根据我们的分析与总结,图片的来源有拍照和相册,而可采取的操作有
使用Bitmap并返回数据使用Uri不返回数据前面我们了解到,使用Bitmap有可能会导致图片过大,而不能返回实际大小的图片,我将采用大图Uri,小图Bitmap的数据存储方式。
我们将要使用到URI来保存拍照后的图片:
1private static final String IMAGE_FILE_LOCATION = " file2Uri imageUri = Uri.parse(IMAGE_FILE_LOCATION);//The Uri to store the big bitmap不难知道,我们从相册选取图片的Action为Intent.ACTION_GET_CONTENT。
根据我们上一篇博客的分析,我准备好了两个实例的Intent。
一、从相册截大图:
Intent intent = new Intent(Intent.ACTION_GET_CONTENT, null);intent.setType("image/*");intent.putExtra("crop", "true");intent.putExtra("aspectX", 2);intent.putExtra("aspectY", 1);intent.putExtra("outputX", );intent.putExtra("outputY", );intent.putExtra("scale", true);intent.putExtra("return-data", false);intent.putExtra(MediaStore.EXTRA_OUTPUT, imageUri);intent.putExtra("outputFormat", Bitmap.CompressFormat.JPEG.toString());intent.putExtra("noFaceDetection", true); // no face detectionstartActivityForResult(intent, CHOOSE_BIG_PICTURE); 二、从相册截小图Intent intent = new Intent(Intent.ACTION_GET_CONTENT, null);intent.setType("image/*");intent.putExtra("crop", "true");intent.putExtra("aspectX", 2);intent.putExtra("aspectY", 1);intent.putExtra("outputX", );intent.putExtra("outputY", );intent.putExtra("scale", true);intent.putExtra("return-data", true);intent.putExtra("outputFormat", Bitmap.CompressFormat.JPEG.toString());intent.putExtra("noFaceDetection", true); // no face detectionstartActivityForResult(intent, CHOOSE_SMALL_PICTURE); 三、对应的onActivityResult可以这样处理返回的数据switch (requestCode) {case CHOOSE_BIG_PICTURE: Log.d(TAG, "CHOOSE_BIG_PICTURE: data = " data);//it seems to be null if(imageUri != null){ Bitmap bitmap = decodeUriAsBitmap(imageUri);//decode bitmap imageView.setImageBitmap(bitmap); } break;case CHOOSE_SMALL_PICTURE: if(data != null){ Bitmap bitmap = data.getParcelableExtra("data"); imageView.setImageBitmap(bitmap); }else{ Log.e(TAG, "CHOOSE_SMALL_PICTURE: data = " data); } break;default: break;}private Bitmap decodeUriAsBitmap(Uri uri){ Bitmap bitmap = null; try { bitmap = BitmapFactory.decodeStream(getContentResolver().openInputStream(uri)); } catch (FileNotFoundException e) { e.printStackTrace(); return null; } return bitmap;}效果图:
大图小图Android判断用户2G/3G/4G移动数据网络 在做AndroidApp的时候,为了给用户省流量,为了不激起用户的愤怒,为了更好的用户体验,是需要根据用户当前网络情况来做一些调整的,也可以在App的
Android中View转换为Bitmap及getDrawingCache=null的解决方法 1.前言Android中经常会遇到把View转换为Bitmap的情形,比如,对整个屏幕视图进行截屏并生成图片;Coverflow中需要把一页一页的view转换为Bitmap、以便实现复
Android软键盘的隐藏显示研究 Android是一个针对触摸屏专门设计的操作系统,当点击编辑框,系统自动为用户弹出软键盘,以便用户进行输入。那么,弹出软键盘后必然会造成原有布
标签: android图片裁剪
本文链接地址:https://www.jiuchutong.com/biancheng/386010.html 转载请保留说明!友情链接: 武汉网站建设