从Android图库裁剪图像 [英] Crop an image from gallery in android

查看:212
本文介绍了从Android图库裁剪图像的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我要当它从gallery.My选择从模拟器种植code的工作,但在手机上不能正常工作在我的应用程序裁剪图像。我设置outputX = 400和outputY = 487。
在我的模拟我得到400×487分辨率的输出位图,但是当我从手机画廊裁剪图像我得到的输出与位图145点¯x177的分辨率。为什么会发生?我对裁剪code以下

给出

 意向意图=新意图(com.android.camera.action.CROP);intent.setType(图像/ *);
intent.setAction(Intent.ACTION_GET_CONTENT);intent.putExtra(裁剪,真);
intent.putExtra(aspectX,500);
intent.putExtra(aspectY,750);
intent.putExtra(规模化,真正的);
intent.putExtra(outputX,400);
intent.putExtra(outputY,487);
intent.putExtra(回归数据,真正的);
startActivityForResult(Intent.createChooser(原意,使用完整的行动),PICK_FROM_GALLERY);

在的onActivityResult

 如果(要求code == PICK_FROM_GALLERY){
捆绑extras2 = data.getExtras();
如果(extras2!= NULL){
位图BM = extras2.getParcelable(数据);
imgview.setImageBitmap(照片);}


解决方案

  buttonGallery.setOnClickListener(新View.OnClickListener(){@覆盖
公共无效的onClick(视图v){
// TODO自动生成方法存根
意向意图=新的Intent();
//调用Android的默认图库
intent.setType(图像/ *);
intent.setAction(Intent.ACTION_GET_CONTENT);
// ******** code作物图像
intent.putExtra(裁剪,真);
intent.putExtra(aspectX,0);
intent.putExtra(aspectY,0);
intent.putExtra(outputX,200);
intent.putExtra(outputY,150);尝试{intent.putExtra(回归数据,真正的);
startActivityForResult(Intent.createChooser(意向,
完全用行动),PICK_FROM_GALLERY);}赶上(ActivityNotFoundException E){
//什么都不做,现在
}
}
});

或参考这些网站以获得更多帮助:

http://www.londatiga.net/featured-articles/how-to-select-and-crop-image-on-android/ http://www.androidhub4you.com /2012/07/how-to-crop-image-from-camera-and.html

I want to crop an image in my application when it is selected from gallery.My cropping code work from the simulator but not properly work on phones. I set outputX=400 and outputY =487. In my simulator i get the output bitmap with 400 x 487 resolution,but when i cropped the image from phone gallery i get the output bitmap with 145 x 177 resolution. Why does it happen? My code for cropping is given below

Intent intent = new Intent("com.android.camera.action.CROP");

intent.setType("image/*");
intent.setAction(Intent.ACTION_GET_CONTENT);

intent.putExtra("crop", "true");
intent.putExtra("aspectX", 500);
intent.putExtra("aspectY", 750);
intent.putExtra("scale", true);
intent.putExtra("outputX", 400);
intent.putExtra("outputY", 487);
intent.putExtra("return-data", true);
startActivityForResult(Intent.createChooser(intent,"Complete action using"), PICK_FROM_GALLERY);

On onActivityResult

if (requestCode == PICK_FROM_GALLERY) {
Bundle extras2 = data.getExtras();
if (extras2 != null) {
Bitmap bm = extras2.getParcelable("data");
imgview.setImageBitmap(photo);}

解决方案

buttonGallery.setOnClickListener(new View.OnClickListener() {

@Override
public void onClick(View v) {
// TODO Auto-generated method stub
Intent intent = new Intent();
// call android default gallery
intent.setType("image/*");
intent.setAction(Intent.ACTION_GET_CONTENT);
// ******** code for crop image
intent.putExtra("crop", "true");
intent.putExtra("aspectX", 0);
intent.putExtra("aspectY", 0);
intent.putExtra("outputX", 200);
intent.putExtra("outputY", 150);

try {

intent.putExtra("return-data", true);
startActivityForResult(Intent.createChooser(intent,
"Complete action using"), PICK_FROM_GALLERY);

} catch (ActivityNotFoundException e) {
// Do nothing for now
}
}
});

or Refer these sites for more help:

http://www.londatiga.net/featured-articles/how-to-select-and-crop-image-on-android/ http://www.androidhub4you.com/2012/07/how-to-crop-image-from-camera-and.html

这篇关于从Android图库裁剪图像的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆