从Android gallery获取图像到C#

从Android gallery获取图像到C#,c#,android,image,unity3d,C#,Android,Image,Unity3d,我正在Unity中创建一个android应用程序(我正在用C#编写代码),我几乎完成了,只需要添加一些最后的调整就可以了。目前,我在获取用户配置文件的配置文件图片时遇到问题。我希望当用户按下一个按钮,他的android gallery就会打开,当他选择一张图片时,它会显示在应用程序中,并发送到数据库。像这样的 public Button ChangeImage; public Image ProfilePicture; void Start() { ChangeImage.onClic

我正在Unity中创建一个android应用程序(我正在用C#编写代码),我几乎完成了,只需要添加一些最后的调整就可以了。目前,我在获取用户配置文件的配置文件图片时遇到问题。我希望当用户按下一个按钮,他的android gallery就会打开,当他选择一张图片时,它会显示在应用程序中,并发送到数据库。像这样的

public Button ChangeImage;
public Image ProfilePicture;

void Start()
{
    ChangeImage.onClick.AddListener(ChangeImageClicked);
}

void ChangeImageClicked()
{
    //here gallery would open and selected image would be returned
    //ProiflePicture = ChoosenImage
}

我在谷歌上搜索了大约一周的解决方案,但没有找到。我读过一些意向书,但C#不认识。所有的帮助都将非常重要。

有各种插件可以很好地为您处理这些问题。其中之一是。 我自己用过一个项目

我的代码片段:

public Image LocalProfileImage;

public void ShowMediaPicker()
{
    if (Application.isEditor)
    {
        // Do something else, since the plugin does not work inside the editor
    }
    else
    {
        NativeGallery.GetImageFromGallery((path) =>
        {
            UploadNewProfileImage(path);
            Texture2D texture = NativeGallery.LoadImageAtPath(path);
            if (texture == null)
            {
                Debug.Log("Couldn't load texture from " + path);
                return;
            }

            LocalProfileImage.sprite = Sprite.Create(texture, new Rect(0, 0, texture.width, texture.height), Vector2.zero);
        });
    }
}

UploadNewProfileImage(路径)
是我的一个函数,它将图像发送到数据库。基本上,您应该从路径中检索图像,然后使用streamreader将其转换为字节

非常感谢你。起初它不起作用,因为我忘了取消对函数调用的注释。但现在它起作用了。这正是我花了几个小时寻找的东西。再次感谢。