From e14383aef7d92c6702146d9a5e0efeb46bf74ced Mon Sep 17 00:00:00 2001 From: alexiscatnip Date: Sun, 16 Jan 2022 10:52:21 +0800 Subject: [PATCH] fix ManagedImage->T2D color conversion (ExportTex2D) --- .../LibreMetaverse/Imaging/ManagedImage.cs | 26 ++++++------------- 1 file changed, 8 insertions(+), 18 deletions(-) diff --git a/Assets/Plugins/LibreMetaverse/Imaging/ManagedImage.cs b/Assets/Plugins/LibreMetaverse/Imaging/ManagedImage.cs index 6be2de4..0c7b7d4 100644 --- a/Assets/Plugins/LibreMetaverse/Imaging/ManagedImage.cs +++ b/Assets/Plugins/LibreMetaverse/Imaging/ManagedImage.cs @@ -460,39 +460,29 @@ namespace OpenMetaverse.Imaging } } - Texture2D b = new Texture2D(Width, Height); + Texture2D b = new Texture2D(Width, Height,TextureFormat.ARGB32,false); b.hideFlags = HideFlags.HideAndDontSave; //this helps us delete this texture later? - var mip0Data = b.GetPixelData(1); + var mip0Data = b.GetPixelData(0); if (mip0Data.Length != Width * Height) { - Debug.LogError("mip0 data size (of texture) not match the data size of array!"); - + Debug.LogError("mip0 data size (of texture) not match the data size of array! " + + (mip0Data.Length).ToString() + " vs "+ (Width * Height).ToString() + ); } + //copy managedinage bytes into the nativearray for (int i = 0; i < mip0Data.Length; i++) { var blue = raw[i * 4 + 0]; var green = raw[i * 4 + 1]; var red = raw[i * 4 + 2]; var alpha = raw[i * 4 + 3]; - mip0Data[i] = new Color32(red, green, blue, alpha); + mip0Data[i] = new Color32(alpha, red, green, blue); } - //Bitmap b = new Bitmap( - // Width, - // Height, - // PixelFormat.Format32bppArgb); - - //BitmapData bd = b.LockBits(new Rectangle(0, 0, b.Width, b.Height), - // ImageLockMode.WriteOnly, - // PixelFormat.Format32bppArgb); - - //System.Runtime.InteropServices.Marshal.Copy(raw, 0, bd.Scan0, Width * Height * 4); - - //b.UnlockBits(bd); - + b.LoadRawTextureData(mip0Data); b.Apply(false); return b; }