- Home /
Question by
xpkoalz · Apr 13, 2015 at 05:55 PM ·
createandroid iphonetexture compression
Image captured and stored from IOS device won't display when access from Unity Editor
Hi,
Heres the problem:
Image created and uploaded from iphone - will download and display fine on iPhone. But if I try to access it from Unity editor (desktop) or an Android device, the image won't show. I've checked the folder where the images were downloaded (Application.persistentDataPath) and the images are there, just that it won't display in unity if its on a different device.
It is the same issue if the images were created and uploaded from desktop, then it will only show when I try to access it from desktop. I hope I make sense here..anyone can offer explanation for this?
heres the code:
// write to file...
Texture2D tex = new Texture2D ((int)Screen.width, (int)rectHt, TextureFormat.ARGB32, false);
Rect readArea = new Rect (0, Screen.height - (rectY + rectHt), Screen.width, rectHt);
yield return new WaitForEndOfFrame ();
tex.ReadPixels (readArea, 0, 0, false);
tex.Apply ();
byte[] bytes = tex.EncodeToJPG ();
imagepath = Application.persistentDataPath + "/img.jpeg";
FileManager.SaveImageFile ( imagepath, bytes);
// loading from file...
if (File.Exists (imagepath)) {
bytes = File.ReadAllBytes (imagepath);
tex = new Texture2D (1, 1, TextureFormat.ARGB32, false);
tex.LoadImage (bytes);
sprite = Sprite.Create (tex, new Rect (0, 0, tex.width, tex.height), new Vector2 (0, 0));
displayObj.GetComponent<Image> ().overrideSprite = sprite;
}
Comment
Your answer
Follow this Question
Related Questions
Can unity create a continuase world?? 3 Answers
Create Unity scenes programatically 3 Answers
create lightning 0 Answers
How to create inputs? 2 Answers