【问题标题】:How do you add a gallery image (user Image) to your drawable folder?如何将图库图像(用户图像)添加到可绘制文件夹?
【发布时间】: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 文件。这是一个很长的故事,为什么我要这样做,但这正是我必须做的:/。如果有人能提供示例代码,那就太棒了!

【问题讨论】:

标签: android android-drawable


【解决方案1】:

可绘制文件夹在您的 apk 中编译,不能在运行时修改。如果您要存储图像,您可以随时使用应用程序的沙箱目录(即 /data/data/application_package)。此处存储的文件不会在图库或任何其他没有 root 权限的资源管理器中列出。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-03-21
    相关资源
    最近更新 更多