前提・実現したいこと
実機でカメラロールから写真(iM程度)を何回か読み込むとこけてしまいます。
参考URL
発生している問題・エラーメッセージ
参考URLのGitHubをダウンロードして使っているだけです。
実機なのでこけてもエラー表示が出ないので何が原因かわからないのですが,
Button1でカメラロールから,1M以上の写真を何回か表示するとこけます。
只,カメラロールからではなくダイレクトにButton2をクリックして表示するテストでは何回でも表示されます。
該当のソースコード
Unity
1using System.Collections; 2using System.Collections.Generic; 3using UnityEngine; 4using UnityEngine.UI; 5using System.Runtime.InteropServices; 6 7public class GameController : MonoBehaviour 8{ 9 [DllImport ("__Internal")] 10 private static extern float OpenCameraRoll (string path); 11 12 public Image image; 13 public int d_no; 14 15 void Start() 16 { 17 d_no = 0; 18 } 19 20 public void OnButtonClick (int number) 21 { 22 if (number == 0) 23 { 24 Debug.Log("click"); 25 26 if (Application.isEditor) 27 { 28 29 } 30 else if (Application.platform == RuntimePlatform.IPhonePlayer) 31 { 32 OpenCameraRoll(Application.temporaryCachePath + "/tempImage"); 33 } 34 else if (Application.platform == RuntimePlatform.Android) 35 { 36 AndroidJavaClass nativeDialog = new AndroidJavaClass("com.wapa5pow.plugin.CameraRoll"); 37 38 AndroidJavaClass unityPlayer = new AndroidJavaClass("com.unity3d.player.UnityPlayer"); 39 AndroidJavaObject context = unityPlayer.GetStatic<AndroidJavaObject>("currentActivity"); 40 41 context.Call("runOnUiThread", new AndroidJavaRunnable(() => { 42 nativeDialog.CallStatic( 43 "openCameraRoll", 44 context, 45 Application.temporaryCachePath + "/tempImage" 46 ); 47 })); 48 49 } 50 } 51 52 if (number == 1) 53 { 54 d_no += 1; 55 Texture2D texture2D = new Texture2D(2, 2); 56 57 if (d_no == 4) 58 { 59 d_no = 1; 60 } 61 if (d_no == 1) 62 { 63 texture2D = Resources.Load<Texture2D>("DSC_0019"); 64 } 65 if (d_no == 2) 66 { 67 texture2D = Resources.Load<Texture2D>("DSC_0020"); 68 } 69 if (d_no == 3) 70 { 71 texture2D = Resources.Load<Texture2D>("DSC_0021"); 72 } 73 Sprite sprite = Sprite.Create(texture2D, new Rect(0, 0, texture2D.width, texture2D.height), 0.5f * Vector2.one); 74 image.sprite = sprite; 75 } 76 } 77 78 public void SetImage (string path) 79 { 80 Texture2D texture2D = new Texture2D (2, 2); 81 texture2D.LoadImage (System.IO.File.ReadAllBytes (path)); 82 Sprite sprite = Sprite.Create (texture2D, new Rect (0, 0, texture2D.width, texture2D.height), 0.5f * Vector2.one); 83 image.sprite = sprite; 84 } 85} 86 87
試したこと
実機にて
あなたの回答
tips
プレビュー