diff --git a/.vs/SpineViewerWPF/FileContentIndex/775c331c-da64-4c7a-bf11-5e016d80d767.vsidx b/.vs/SpineViewerWPF/FileContentIndex/775c331c-da64-4c7a-bf11-5e016d80d767.vsidx new file mode 100644 index 0000000..09efc87 Binary files /dev/null and b/.vs/SpineViewerWPF/FileContentIndex/775c331c-da64-4c7a-bf11-5e016d80d767.vsidx differ diff --git a/.vs/SpineViewerWPF/v17/.suo b/.vs/SpineViewerWPF/v17/.suo new file mode 100644 index 0000000..25f896a Binary files /dev/null and b/.vs/SpineViewerWPF/v17/.suo differ diff --git a/.vs/SpineViewerWPF/v17/fileList.bin b/.vs/SpineViewerWPF/v17/fileList.bin new file mode 100644 index 0000000..ee396af Binary files /dev/null and b/.vs/SpineViewerWPF/v17/fileList.bin differ diff --git a/SpineViewerWPF/PublicFunction/Common.cs b/SpineViewerWPF/PublicFunction/Common.cs index fb95268..208edb3 100644 --- a/SpineViewerWPF/PublicFunction/Common.cs +++ b/SpineViewerWPF/PublicFunction/Common.cs @@ -10,7 +10,9 @@ using System; using System.Collections.Generic; using System.Drawing; +using System.Drawing.Imaging; using System.IO; +using System.Runtime.InteropServices; using System.Threading; using System.Windows; using System.Windows.Media.Imaging; @@ -142,7 +144,7 @@ public static void RecodingEnd(float AnimationEnd) for (int i = 0; i < App.globalValues.GifList.Count; i++) { MemoryStream ms = new MemoryStream(); - App.globalValues.GifList[i].SaveAsPng(ms, App.globalValues.GifList[i].Width, App.globalValues.GifList[i].Height); + MySaveAsPng(App.globalValues.GifList[i], ms, App.globalValues.GifList[i].Width, App.globalValues.GifList[i].Height); lms.Add(ms); App.globalValues.GifList[i].Dispose(); } @@ -347,7 +349,7 @@ public static void SaveToPng(Texture2D texture2D) { using (var fs = (FileStream)saveFileDialog.OpenFile()) { - texture2D.SaveAsPng(fs, texture2D.Width, texture2D.Height); + MySaveAsPng(texture2D, fs, texture2D.Width, texture2D.Height); } } @@ -384,7 +386,7 @@ public static void TakeRecodeScreenshot(GraphicsDevice _graphicsDevice) using (FileStream fs = new FileStream($"{exportDir}{fileName}_{App.recordImageCount.ToString().PadLeft(7,'0')}.png" ,FileMode.Create)) { - texture.SaveAsPng(fs, _graphicsDevice.PresentationParameters.BackBufferWidth + MySaveAsPng(texture, fs, _graphicsDevice.PresentationParameters.BackBufferWidth , _graphicsDevice.PresentationParameters.BackBufferHeight); } App.recordImageCount++; @@ -445,6 +447,32 @@ public static void SetInitLocation(float height) } } + + public static void MySaveAsPng(Texture2D texture, Stream ms, int width, int height) + { + ImageFormat imageFormat = ImageFormat.Png; + using (Bitmap bitmap = new Bitmap(width, height, PixelFormat.Format32bppArgb)) + { + byte blue; + IntPtr safePtr; + BitmapData bitmapData; + System.Drawing.Rectangle rect = new System.Drawing.Rectangle(0, 0, width, height); + byte[] textureData = new byte[4 * width * height]; + + texture.GetData(textureData); + for (int i = 0; i < textureData.Length; i += 4) + { + blue = textureData[i]; + textureData[i] = textureData[i + 2]; + textureData[i + 2] = blue; + } + bitmapData = bitmap.LockBits(rect, ImageLockMode.WriteOnly, PixelFormat.Format32bppArgb); + safePtr = bitmapData.Scan0; + Marshal.Copy(textureData, 0, safePtr, textureData.Length); + bitmap.UnlockBits(bitmapData); + bitmap.Save(ms, imageFormat); + } + } }