android开发_拍照后上传前的处理

RT

1、直接压缩处理显示到ImageView


protected void onActivityResult(int requestCode, int resultCode, Intent data) {
		super.onActivityResult(requestCode, resultCode, data);
		if (requestCode == REQUEST_CODE) {
			if (resultCode != RESULT_OK) {
				return;
			}
			if (file != null && file.exists()) {
				BitmapFactory.Options options = new BitmapFactory.Options();
				options.inSampleSize = 2;
				photo = BitmapFactory.decodeFile(file.getPath(), options);
				photo_image.setBackgroundDrawable(new BitmapDrawable(photo));
				pictureDir = file.getPath();
			} else {
				Toast.makeText(this, R.string.photo_file_isnull,
						Toast.LENGTH_LONG).show();
			}
		}
	}

2、先截图处理再显示到ImageView

<span style="white-space:pre">	</span>@Override
	protected void onActivityResult(int requestCode, int resultCode, Intent data) {

		if (requestCode == 1) {
			Log.i("LPY_DEBUG","拍照后的图片路径为 "+photoFile);
			// if(photoFile != null && )
			if (photoFile != null && photoFile.exists() && photoFile.length() > 0) {
				startPhotoZoom(Uri.fromFile(photoFile));
			}
		}
		if (requestCode == 3) {
			if (data != null) {
				Bundle bundle = data.getExtras();
				if (bundle != null) {
					// 裁剪后的图片
					bitmap = bundle.getParcelable("data");
					if (<span style="font-family: 'Microsoft YaHei';">bitmap</span>!= null) {
						Log.i("LPY_DEBUG","进入获取data数据的判断");
						iv_userphoto.setImageBitmap(bitmap);
						photoFile = new File(Constans.PHOTO_DIR, System.currentTimeMillis() + ".jpg");							// 将图片转换成文件
						ImageUtil.saveBitmapToJepgFile(bitmap, photoFile);			
					}	
				}
		}
		super.onActivityResult(requestCode, resultCode, data);
	}

	private void startPhotoZoom(Uri uri) {

		Intent intent = new Intent("com.android.camera.action.CROP");
		intent.setDataAndType(uri, "image/*");
		// crop为true是设置在开启的intent中设置显示的view可以剪裁
		intent.putExtra("crop", "true");//发送裁剪信号

		// aspectX aspectY 是宽高的比例
		intent.putExtra("aspectX", 300);//X方向上的比例
		intent.putExtra("aspectY", 190);//Y方向上的比例

		// outputX,outputY 是剪裁图片的宽高
		intent.putExtra("outputX", 300);//裁剪区的宽
		intent.putExtra("outputY", 190);//裁剪区的高
		intent.putExtra("return-data", true);//是否返回数据
		intent.putExtra("noFaceDetection", true);//关闭人脸检测
		intent.putExtra("scale",true);//是否保留比例
		startActivityForResult(intent, 3);

	}


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值