0
我有一些问题与设置一个ImageView从画廊意图返回的对象。我一定在做错事,但是当我调试它时,一切似乎都在正确的地方。它不会抛出任何例外,它只是将我的形象改变为无。Android的图像库裁剪图像和设置ImageView
我正试图按照其他指南和教程在stackoverflow得到我的答案,但我不能让它工作。
这个调用画廊很好,但它不允许croping ...
public void onViewCreated(View view, Bundle savedInstanceState) {
final ImageView profileImage = (ImageView) view.findViewById(R.id.profile_user_image);
profileImage.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Intent i = new Intent(Intent.ACTION_PICK, android.provider.MediaStore.Images.Media.EXTERNAL_CONTENT_URI);
startActivityForResult(i, RESULT_LOAD_IMAGE);
}
});
}
@Override
public void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
if (requestCode == RESULT_LOAD_IMAGE && resultCode == Activity.RESULT_OK && null != data) {
if (requestCode == RESULT_LOAD_IMAGE && resultCode == Activity.RESULT_OK && null != data) {
Uri picUri = data.getData();
String[] filePathColumn = {MediaStore.Images.Media.DATA};
Cursor cursor = getActivity().getContentResolver().query(picUri,
filePathColumn, null, null, null);
cursor.moveToFirst();
int columnIndex = cursor.getColumnIndex(filePathColumn[0]);
filePath = cursor.getString(columnIndex);
cursor.close();
// Set The Bitmap Data To ImageView
BitmapFactory.Options o = new BitmapFactory.Options();
o.inPreferredConfig = Bitmap.Config.ARGB_8888;
o.inScaled = true;
ImageView bitmapview = (ImageView) _this.findViewById(R.id.profile_user_image);
bitmapview.setScaleType(ImageView.ScaleType.FIT_XY);
//bitmapview.setImageResource(R.drawable.female_icon); // KNOWN FILE
bitmapview.setImageBitmap(BitmapFactory.decodeFile(filePath,o)); // Gallery File.
}
}
}
我不知道我缺少什么,在 的ImageView的限制为150dp X 150dp
我已经尝试将其更改为可以正常工作的已知资源,但每次使用此方法都会失败,无论我尝试什么。