【发布时间】:2015-08-18 03:55:32
【问题描述】:
所以我想将从用户画廊获得的图像存储到我的可绘制文件夹中,但我不知道该怎么做?有人可以帮我吗!我有图像的路径,但我想成为我的可绘制文件夹中的一个文件。
谢谢。
private void grabImage()
{
Intent imageGetter = new Intent(Intent.ACTION_PICK, MediaStore.Images.Media.EXTERNAL_CONTENT_URI);
startActivityForResult(imageGetter, RESULT_LOAD_IMAGE);
}
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data)
{
super.onActivityResult(requestCode, resultCode, data);
if(requestCode == RESULT_LOAD_IMAGE && resultCode == RESULT_OK && null != data)
{
Uri selectedImage = data.getData();
String[] filePathColumn = {MediaStore.Images.Media.DATA};//Array size of 1, and we put in a string
Cursor cursor = getContentResolver().query(selectedImage, filePathColumn, null, null, null);
cursor.moveToFirst();
int columnIndex = cursor.getColumnIndex(filePathColumn[0]);
user_image_path = cursor.getString(columnIndex);//here we have our image path.
cursor.close();
ImageView imageView = (ImageView) findViewById(R.id.imageView);
imageView.setImageBitmap(BitmapFactory.decodeFile(user_image_path));
}
//Sending our images.
sendInformation.putExtra("imagePath", user_image_path);
}
所以在我抓取图像并将其发送后,我还想知道如何将该图像路径字符串转换为我可以随时参考的 Drawable 文件。这是一个很长的故事,为什么我要这样做,但这正是我必须做的:/。如果有人能提供示例代码,那就太棒了!
【问题讨论】:
-
drawable 文件夹是嵌入到您的 apk 中的编译资源。您不能在运行时更改它。