我有一个应用程序,用户可以在其中为他们在图库中的个人资料上传图片。
为了实现这一点,我将图像的路径保存在共享首选项中,并将图像 uri 放在 imageView 中。
一切正常,但是当用户下载图像时,尺寸变量 imageView 不是很漂亮,所以我想像 whatsapp 那样提供一个图像大小来尊重个人资料,这样所有用户的个人资料图像都有相同的尺寸。
请问我该如何实施?
这是我在图库中选择图像所做的
Intent intent;
if (Build.VERSION.SDK_INT < 19) {
intent = new Intent(Intent.ACTION_GET_CONTENT);
} else {
intent = new Intent(Intent.ACTION_OPEN_DOCUMENT);
intent.addCategory(Intent.CATEGORY_OPENABLE);
}
intent.setType("image/*");
startActivityForResult(Intent.createChooser(intent, "Select Picture"), PICK_IMAGE);
和
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
if (requestCode == PICK_IMAGE) {
if (resultCode == RESULT_OK) {
if (data != null) {
mImageUri = data.getData();
SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(this);
SharedPreferences.Editor editor = preferences.edit();
editor.putString("image", String.valueOf(mImageUri));
editor.commit();
imageView.setImageURI(mImageUri);
imageView.invalidate();
}
}
}
}