毕业论文开发语言企业开发JAVA技术.NET技术WEB开发Linux/Unix数据库技术Windows平台移动平台嵌入式论文范文英语论文
您现在的位置: 毕业论文 >> 移动平台 >> 正文

Android使用系统的照片裁剪功能后怎么获得图片裁剪后的uri呢

更新时间:2012-8-18:  来源:毕业论文

Android使用系统的照片裁剪功能后怎么获得图片裁剪后的uri呢

1.使用的Intent intent = new Intent("com.android.camera.action.CROP");可是data.getExtras().getParcelable("data");得到的是bitmap,我想得到uri,应该怎么得到呢?这个裁剪功能是把原来的图裁剪完之后保存那个到原来那个文件还是只是在缓存里面,不保存等关闭这个应用就没有了?

2.我裁剪之后点击保存,一直停留在正在裁剪照片那里不动,怎么回事呢?

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

 intent.setDataAndType(uri, "image/*");

 intent.putExtra("crop", "true");

 intent.putExtra("return-data", true);

 startActivityForResult(intent, 1);

 @Override

 protected void onActivityResult(int requestCode, int resultCode, Intent data) {

 // TODO Auto-generated method stub

 if (resultCode == RESULT_OK) {

 bitmap = data.getExtras().getParcelable("data");

local.setImageBitmap(bitmap);

 }

 super.onActivityResult(requestCode, resultCode, data);

 }private class SaveOutput implements Job<Intent> {
  private final RectF mCropRect;

  public SaveOutput(RectF cropRect) {
  mCropRect = cropRect;
  }

  public Intent run(JobContext jc) {
  RectF cropRect = mCropRect;
  Bundle extra = getIntent().getExtras();

  Rect rect = new Rect(
  Math.round(cropRect.left), Math.round(cropRect.top),
  Math.round(cropRect.right), Math.round(cropRect.bottom));

  Intent result = new Intent();
  result.putExtra(KEY_CROPPED_RECT, rect);
  Bitmap cropped = null;
  boolean outputted = false;
  if (extra != null) {
  Uri uri = (Uri) extra.getParcelable(MediaStore.EXTRA_OUTPUT);
  if (uri != null) {
  if (jc.isCancelled()) return null;
  outputted = true;
  cropped = getCroppedImage(rect);
  if (!saveBitmapToUri(jc, cropped, uri)) return null;
  }
  if (extra.getBoolean(KEY_RETURN_DATA, false)) {
  if (jc.isCancelled()) return null;
  outputted = true;
  if (cropped == null) cropped = getCroppedImage(rect);
  result.putExtra(KEY_DATA, cropped);
  }
  if (extra.getBoolean(KEY_SET_AS_WALLPAPER, false)) {
  if (jc.isCancelled()) return null;
  outputted = true;
  if (cropped == null) cropped = getCroppedImage(rect);
  if (!setAsWallpaper(jc, cropped)) return null;
  }
  }
  if (!outputted) {
  if (jc.isCancelled()) return null;
  if (cropped == null) cropped = getCroppedImage(rect);
  Uri data = saveToMediaProvider(jc, cropped);
  if (data != null) result.setData(data);
  }
  return result;
  }
  }
看到了么?
根据你发起的时候的参数,会返回不同的值,默认返回下面:
  Uri data = saveToMediaProvider(jc, cropped);
  if (data != null) result.setData(data);

你可以上android源码里面的CropImage.java这个类里面看看
我觉得调用系统的裁剪,可以自己传个Uri过去吧。
比如你想把裁剪后的图片存到/mnt/sdcard/test/crop_xxx.jpg
那么
File file = new File("/mnt/sdcard/test/crop_xxx.jpg");
Uri uri = Uri.fromFile(file);

启动crop程序的时候,你再把这个uri作为参数传过去
key为MediaStore.EXTRA_OUTPUT

设为首页 | 联系站长 | 友情链接 | 网站地图 |

copyright©youerw.com 优尔论文网 严禁转载
如果本毕业论文网损害了您的利益或者侵犯了您的权利,请及时联系,我们一定会及时改正。