所以我想存储我从用户的图库到我的可绘制文件夹的图像,但我不知道如何做到这一点?有人能帮我一下吗? !我有图像的路径,但我想成为一个文件在我的可绘制文件夹。
谢谢。
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文件。这是一个很长的故事为什么我想这样做,但这就是我必须做的:/。如果有人能提供示例代码,那将是惊人的!
可绘制文件夹在您的apk中编译,不能在运行时修改。如果你正在寻找存储图像,你总是可以使用应用程序的沙箱目录(i。e/数据/数据/application_package)。存储在这里的文件将不会在没有root权限的库或任何其他资源管理器中列出。