选择并修剪出在Android的最大尺寸出在、尺寸、最大、Android

由网友(爱过痛过姑娘我心如刀割、)分享简介:我想这样做是显示裁剪框,但是它的最大尺寸是什么。类似的东西:意向意图=新的意图();intent.setType(图像/ *);intent.putExtra(裁剪,真);intent.putExtra(最大宽度,30);intent.putExtra(最大高度,30);intent.setAction(Intent....

我想这样做是显示裁剪框,但是它的最大尺寸是什么。类似的东西:

 意向意图=新的意图();
    intent.setType(图像/ *);
    intent.putExtra(裁剪,真);

    intent.putExtra(最大宽度,30);
    intent.putExtra(最大高度,30);
    intent.setAction(Intent.ACTION_GET_CONTENT);
    startActivityForResult(Intent.createChooser(意向,
            选择图片),IMAGE_SELECTED);
 

解决方案

试试这个:

  //照片的意图。
意向意图=新的意图(Intent.ACTION_GET_CONTENT,NULL);
intent.setType(图像/ *);

//意图参数。
intent.putExtra(裁剪,真);
intent.putExtra(aspectX,30); //这台最大宽度。
intent.putExtra(aspectY,30); //这台最大高度。
intent.putExtra(outputX,1);
intent.putExtra(outputY,1);
intent.putExtra(规模化,真正的);
intent.putExtra(回归数据,真正的);
intent.putExtra(MediaStore.EXTRA_OUTPUT,newImageFile());
intent.putExtra(OUTPUTFORMAT,Bitmap.Com pressFormat.JPEG.toString());

//发送意图。
activity.startActivityForResult(意向,BibleActivity.CROP_PHOTO_REQUEST_ code);
 

要获得新的映像文件:

  / **
 *创建裁剪后的图像新的临时文件。
 * @返回URI
 * /
公共乌里newImageFile(){
  返回Uri.fromFile(CREATEFILE(CROPPED_FILENAME));
}

/ **
 *创建文件。
 * @返回文件。
 * /
私人文件的CreateFile(字符串文件名){

  //确保我们有SD卡。
  如果(isSDCARDMounted()){

    //文件位置。
    档案文件=新的文件(activity.getExternalFilesDir(空),文件名);
    尝试 {
      //删除,如果存在。
      如果(file.exists())
        file.delete();

      //创建新的文件。
      file.createNewFile();

    }赶上(IOException异常E){
      Toast.makeText(活性,R.string.error_cannot_create_temp_file,Toast.LENGTH_LONG).show();
    }
    返回的文件;

  } 其他 {
    Toast.makeText(活动,R.string.error_no_sd_card_ present,Toast.LENGTH_LONG).show();
    返回null;
  }
}


/ **
 *检查,以确保我们有SD卡。
 * @返回
 * /
私人布尔isSDCARDMounted(){
  如果(Environment.getExternalStorageState()。等于(Environment.MEDIA_MOUNTED))
    返回true;
  其他
    返回false;
}
 
报告称苹果大屏手机主导今年圣诞购物季

What I want to do it's to show the crop box, but with a maximum size. Something like that:

    Intent intent = new Intent();
    intent.setType("image/*");
    intent.putExtra("crop", "true");

    intent.putExtra("max-width", 30);
    intent.putExtra("max-height", 30);
    intent.setAction(Intent.ACTION_GET_CONTENT);
    startActivityForResult(Intent.createChooser(intent,
            "Select Picture"), IMAGE_SELECTED);

解决方案

Try this:

// Photo intent.
Intent intent = new Intent(Intent.ACTION_GET_CONTENT, null);
intent.setType("image/*");

// Intent parameters.
intent.putExtra("crop", "true");
intent.putExtra("aspectX", 30); // This sets the max width.
intent.putExtra("aspectY", 30); // This sets the max height.
intent.putExtra("outputX", 1);
intent.putExtra("outputY", 1);
intent.putExtra("scale", true);
intent.putExtra("return-data", true);
intent.putExtra(MediaStore.EXTRA_OUTPUT, newImageFile());
intent.putExtra("outputFormat", Bitmap.CompressFormat.JPEG.toString());

// Send intent.
activity.startActivityForResult(intent, BibleActivity.CROP_PHOTO_REQUEST_CODE);

To get the new image file:

/**
 * Create new temporary file for cropped image.
 * @return uri
 */
public Uri newImageFile() {
  return Uri.fromFile(createFile(CROPPED_FILENAME));        
}

/**
 * Create file.
 * @return file.
 */
private File createFile(String fileName) {

  // Make sure we have SD Card.
  if (isSDCARDMounted()) {

    // File location.
    File file = new File(activity.getExternalFilesDir(null), fileName);
    try {
      // Delete if exist.
      if (file.exists())
        file.delete();

      // Create new file.
      file.createNewFile();

    } catch (IOException e) {
      Toast.makeText(activity, R.string.error_cannot_create_temp_file, Toast.LENGTH_LONG).show();
    }
    return file;

  } else {
    Toast.makeText(activity, R.string.error_no_sd_card_present, Toast.LENGTH_LONG).show();
    return null;
  }
}


/**
 * Check to make sure we have SD Card.
 * @return
 */
private boolean isSDCARDMounted() {
  if (Environment.getExternalStorageState().equals(Environment.MEDIA_MOUNTED))
    return true;
  else
    return false;
}

阅读全文

相关推荐

最新文章