Beispiel #1
0
        public BitmapImplementation(Stream stream)
        {
            Bitmap = new UnityEngine.Texture2D(0, 0);

            byte[] imageData = new byte[stream.Length];
            stream.Read(imageData, 0, (int)stream.Length);
            Bitmap.LoadImage(imageData);
        }
Beispiel #2
0
 public void LoadImage(Stream stream)
 {
     using (var mstream = new MemoryStream()) {
         stream.CopyTo(mstream);
         var data = mstream.GetBuffer();
         unityTexture.LoadImage(data);
     }
 }
Beispiel #3
0
        private static Texture2D PlatformFromStream(GraphicsDevice graphicsDevice, Stream stream)
        {
            UnityEngine.Texture2D unityTexture = new UnityEngine.Texture2D(0, 0);
            BinaryReader          br           = new BinaryReader(stream);

            byte[] data = br.ReadBytes((int)stream.Length);
            unityTexture.LoadImage(data);
            return(new Texture2D(unityTexture));
        }
Beispiel #4
0
        static int _m_LoadImage(RealStatePtr L)
        {
            ObjectTranslator translator = ObjectTranslatorPool.Instance.Find(L);


            UnityEngine.Texture2D __cl_gen_to_be_invoked = (UnityEngine.Texture2D)translator.FastGetCSObj(L, 1);


            int __gen_param_count = LuaAPI.lua_gettop(L);

            try {
                if (__gen_param_count == 2 && (LuaAPI.lua_isnil(L, 2) || LuaAPI.lua_type(L, 2) == LuaTypes.LUA_TSTRING))
                {
                    byte[] data = LuaAPI.lua_tobytes(L, 2);

                    bool __cl_gen_ret = __cl_gen_to_be_invoked.LoadImage(data);
                    LuaAPI.lua_pushboolean(L, __cl_gen_ret);



                    return(1);
                }
                if (__gen_param_count == 3 && (LuaAPI.lua_isnil(L, 2) || LuaAPI.lua_type(L, 2) == LuaTypes.LUA_TSTRING) && LuaTypes.LUA_TBOOLEAN == LuaAPI.lua_type(L, 3))
                {
                    byte[] data            = LuaAPI.lua_tobytes(L, 2);
                    bool   markNonReadable = LuaAPI.lua_toboolean(L, 3);

                    bool __cl_gen_ret = __cl_gen_to_be_invoked.LoadImage(data, markNonReadable);
                    LuaAPI.lua_pushboolean(L, __cl_gen_ret);



                    return(1);
                }
            } catch (System.Exception __gen_e) {
                return(LuaAPI.luaL_error(L, "c# exception:" + __gen_e));
            }

            return(LuaAPI.luaL_error(L, "invalid arguments to UnityEngine.Texture2D.LoadImage!"));
        }
        private Texture2D LoadTexture2D(string asset)
        {
            UnityEngine.Texture2D unityTexture = new UnityEngine.Texture2D(2, 2);

#if ALT_MODE
            unityTexture = (UnityEngine.Texture2D)UnityEngine.Resources.Load(asset);
#else
            byte[] bytes = File.ReadAllBytes(asset);
            unityTexture.LoadImage(bytes);
#endif

            return(new Texture2D(unityTexture));
        }
        public static UnityEngine.Texture2D ReadResourceAsTexture2D(String name)
        {
            byte[] data = ReadResource(name);

            UnityEngine.Texture2D tex = new UnityEngine.Texture2D(1, 1);
            if (tex.LoadImage(data))
            {
                tex.Apply(true);
                return(tex);
            }

            return(null);
        }
Beispiel #7
0
 // Returns false and nulls |texture| if the file does not exist.
 private bool LoadTextureIfExists(out UnityEngine.Texture texture,
                        String path)
 {
     string full_path =
     KSPUtil.ApplicationRootPath + Path.DirectorySeparatorChar +
     "GameData" + Path.DirectorySeparatorChar +
     "Principia" + Path.DirectorySeparatorChar +
     "assets" + Path.DirectorySeparatorChar +
     path;
     if (File.Exists(full_path)) {
       var texture2d = new UnityEngine.Texture2D(2, 2);
       bool success = texture2d.LoadImage(
       File.ReadAllBytes(full_path));
       if (!success) {
     Log.Fatal("Failed to load texture " + full_path);
       }
       texture = texture2d;
       return true;
     } else {
       texture = null;
       return false;
     }
 }
        /** Convert
         */
        public static UnityEngine.Texture2D Convert(byte[] a_binary)
        {
            UnityEngine.Texture2D t_result = null;

            try{
                BinaryType t_type = GetType(a_binary);

                switch (t_type)
                {
                case BinaryType.Png:
                {
                    int t_width;
                    int t_height;
                    if (Png_GetSize(a_binary, out t_width, out t_height) == true)
                    {
                        UnityEngine.Texture2D t_texture = new UnityEngine.Texture2D(t_width, t_height);
                        if (t_texture != null)
                        {
                                                                #if (UNITY_5)
                            if (t_texture.LoadImage(a_binary) == true)
                            {
                                t_result = t_texture;
                            }
                                                                #else
                            if (UnityEngine.ImageConversion.LoadImage(t_texture, a_binary) == true)
                            {
                                t_result = t_texture;
                            }
                                                                #endif
                        }
                    }
                } break;

                case BinaryType.Jpg:
                {
                    int t_width;
                    int t_height;
                    if (Jpg_GetSize(a_binary, out t_width, out t_height) == true)
                    {
                        UnityEngine.Texture2D t_texture = new UnityEngine.Texture2D(t_width, t_height);
                        if (t_texture != null)
                        {
                                                                #if (UNITY_5)
                            if (t_texture.LoadImage(a_binary) == true)
                            {
                                t_result = t_texture;
                            }
                                                                #else
                            if (UnityEngine.ImageConversion.LoadImage(t_texture, a_binary) == true)
                            {
                                t_result = t_texture;
                            }
                                                                #endif
                        }
                    }
                } break;
                }
            }catch (System.Exception t_exception) {
                Tool.DebugReThrow(t_exception);
                t_result = null;
            }

            return(t_result);
        }