Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Binary file not shown.
Binary file added .vs/SpineViewerWPF/v17/.suo
Binary file not shown.
Binary file added .vs/SpineViewerWPF/v17/fileList.bin
Binary file not shown.
34 changes: 31 additions & 3 deletions SpineViewerWPF/PublicFunction/Common.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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();
}
Expand Down Expand Up @@ -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);
}
}

Expand Down Expand Up @@ -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++;
Expand Down Expand Up @@ -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<byte>(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);
}
}
}