tlghn
1
Hello, I am dealing with an interesting issue while trying to load image from mobile device. It’s been hours but still not found a way to fix it.
Here it is: When I pick an image from device gallery, the imported image which is created by Texture2D.LoadImage method creates an “Development Build” image.
Please find the attached screenshot which describes better what I want to say.
Please note: I’ve already check the image path with Debug.Log and everything seems working.
Thanks
Pick Image From Gallery
Result
Here is code for loading image:
private static void OnActivityResult(AndroidJavaObject intent, object data)
{
try
{
var contentUri =
intent.Call<AndroidJavaObject>("getData", new object[0]).Call<string>("toString",
new object[0]);
var cursor =
AndroidCursor.Open
(
contentUri,
new[] {"_data"},
string.Empty,
null,
string.Empty
);
using (cursor)
{
if (!cursor.MoveToNext()) return;
var path = cursor.Get<string>("_data");
Debug.Log(path);
var bytes = File.ReadAllBytes(path);
Debug.Log(bytes.Length);
var tex = new Texture2D(4, 4) { wrapMode = TextureWrapMode.Clamp };
var imageLoaded = tex.LoadImage(bytes);
if (imageLoaded)
{
((OnImagePickedDelegate)data)(tex);
}
}
}
catch (Exception ex)
{
Debug.LogException(ex);
}
}
did you to find solution?,did you find solution?