iLMS知識社群歷程檔登入
位置: 黃國哲 > Unity
1131022 開啟圖片
by 黃國哲 2024-10-22 15:36:02, 回應(0), 人氣(11)
using System.IO;
    public RawImage imageDisplay;
    public void PickImageFromGallery
        NativeGallery.Permission permission = NativeGallery.GetImageFromGallery((path) =>        
            if (path != null)            
                // 加載圖片到Texture2D
                Texture2D texture = NativeGallery.LoadImageAtPath(path, maxSize: 512);
                if (texture == null)               
                    Debug.Log("無法加載圖片.
                    return;               
                // 顯示圖片
                imageDisplay.texture = texture;          
        }, "選擇圖片", "image/*
        Debug.Log("Permission result: " + permission);  


回應