mirror of
https://gitee.com/akwkevin/aistudio.-wpf.-diagram
synced 2026-05-04 06:51:28 +08:00
声音序列化
This commit is contained in:
@@ -2,6 +2,7 @@
|
|||||||
using System.Drawing;
|
using System.Drawing;
|
||||||
using System.Drawing.Imaging;
|
using System.Drawing.Imaging;
|
||||||
using System.IO;
|
using System.IO;
|
||||||
|
using System.IO.Pipes;
|
||||||
using System.Runtime.InteropServices.ComTypes;
|
using System.Runtime.InteropServices.ComTypes;
|
||||||
using System.Windows;
|
using System.Windows;
|
||||||
using System.Windows.Media.Imaging;
|
using System.Windows.Media.Imaging;
|
||||||
@@ -268,5 +269,52 @@ namespace AIStudio.Wpf.DiagramDesigner
|
|||||||
return bitmapImage;
|
return bitmapImage;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static string ToBase64String(this Stream stream)
|
||||||
|
{
|
||||||
|
byte[] bytearray = new byte[stream.Length];
|
||||||
|
stream.Seek(0, SeekOrigin.Begin);
|
||||||
|
stream.Read(bytearray, 0, bytearray.Length);
|
||||||
|
|
||||||
|
return Convert.ToBase64String(bytearray);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static MemoryStream ToMemoryStream(this string base64String, int width = 0, int height = 0)
|
||||||
|
{
|
||||||
|
if (string.IsNullOrEmpty(base64String))
|
||||||
|
return null;
|
||||||
|
|
||||||
|
try
|
||||||
|
{
|
||||||
|
var byteArray = Convert.FromBase64String(base64String);
|
||||||
|
var stream = new MemoryStream(byteArray);
|
||||||
|
stream.Seek(0, SeekOrigin.Begin);
|
||||||
|
|
||||||
|
return stream;
|
||||||
|
}
|
||||||
|
catch
|
||||||
|
{
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public static FileStream ToFileStream(this string base64String, string filename, int width = 0, int height = 0)
|
||||||
|
{
|
||||||
|
if (string.IsNullOrEmpty(base64String))
|
||||||
|
return null;
|
||||||
|
|
||||||
|
try
|
||||||
|
{
|
||||||
|
var byteArray = Convert.FromBase64String(base64String);
|
||||||
|
FileStream fs = new FileStream(filename, FileMode.OpenOrCreate, FileAccess.ReadWrite);
|
||||||
|
fs.Write(byteArray, 0, byteArray.Length);
|
||||||
|
fs.Seek(0, SeekOrigin.Begin);
|
||||||
|
return fs;
|
||||||
|
}
|
||||||
|
catch
|
||||||
|
{
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user