java - 我想裁剪图像以设置配置文件
问题描述
我是新来的,正在学习android开发。我想裁剪图像以设置个人资料图片。当我使用下面的代码时,它没有完成它的跳转来捕捉(出了点问题)。请帮我解决这个问题。在 xml 上使用图像视图并在 mainfest 上获得读写权限。并使用 ArthurHub/Android-Image-Cropper 进行裁剪功能
enter code here select_image.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
premission();
if (pre == 2) {
Intent photoPickerIntent = new Intent(Intent.ACTION_PICK);
Log.d("pp", "pp");
photoPickerIntent.setType("image/*");
startActivityForResult(photoPickerIntent, SELECT_PHOTO);
}
}
});
protected void onActivityResult(int requestCode, int resultCode, Intent data)
{ super.onActivityResult(requestCode, resultCode, data);
try
{
if (requestCode == SELECT_PHOTO && resultCode == RESULT_OK && null != data)
{
CropImage.activity()
.setGuidelines(CropImageView.Guidelines.ON)
.setAspectRatio(1, 1)
.start(this);
Uri selectedImage = data.getData();
}
if (requestCode == CropImage.CROP_IMAGE_ACTIVITY_REQUEST_CODE)
{
CropImage.ActivityResult result = CropImage.getActivityResult(data);
if (resultCode == RESULT_OK)
{
Uri selectedImage = result.getUri();
String[] filePathColumn = {MediaStore.Images.Media.DATA};
Cursor cursor = getContentResolver().query(selectedImage, filePathColumn, null, null, null);
cursor.moveToFirst();
int columnIndex = cursor.getColumnIndex(filePathColumn[0]);
imgDecodableString = cursor.getString(columnIndex);
cursor.close();
profileimage.setImageBitmap(BitmapFactory.decodeFile(imgDecodableString));
Drawable myDrawable = profileimage.getDrawable();
profileimage.buildDrawingCache();
Bitmap bmap = profileimage.getDrawingCache();
BitmapDrawable bitmapDrawable = ((BitmapDrawable) myDrawable);
Bitmap bitmap1 = bitmapDrawable.getBitmap();
final ByteArrayOutputStream stream = new ByteArrayOutputStream();
bitmap1.compress(Bitmap.CompressFormat.JPEG, 60, stream);
imageInByte = stream.toByteArray();
encoded = Base64.encodeToString(imageInByte, Base64.DEFAULT);
} else
{
Toast.makeText(this, "You have not picked Image",
Toast.LENGTH_LONG).show();
}
}
}
catch (Exception e)
{
Toast.makeText(this, "Something went wrong", Toast.LENGTH_LONG).show();
}
}
解决方案
推荐阅读
- c# - 带有事件处理程序的 Autofac 单实例
- vb.net - ms-access "Great Than" 或相等查询
- google-bigquery - 从数组中删除空值/空值
- python - 批量归一化导致训练和推理损失之间的巨大差异
- c# - 将所有 POST 请求路由到 1 个接收 POST 正文的 APIController 方法
- c++ - 将数组传递给 lambda 函数
- python - SkLearn - 为什么 LabelEncoder().fit 仅适用于训练数据
- google-cloud-platform - Google Cloud:GKE 的出站 IP 地址
- pgadmin - 如何让 pgAdmin4 的结果网格加载所有结果?
- c++ - C++ lambda:如何“冻结”局部变量的值?