bug修复

This commit is contained in:
艾竹
2023-08-26 21:30:31 +08:00
parent 045a724ee2
commit d50ec045ea
8 changed files with 130 additions and 33 deletions

View File

@@ -143,7 +143,7 @@ namespace AIStudio.Wpf.DiagramDesigner
{
var bitmap = (imageBrush.ImageSource as BitmapImage);
byte[] bytearray = null;
Stream smarket = bitmap.StreamSource;
Stream smarket = bitmap.StreamSource;
if (smarket != null && smarket.Length > 0)
{
//设置当前位置
@@ -194,21 +194,27 @@ namespace AIStudio.Wpf.DiagramDesigner
public static string ToBase64String(this BitmapImage bitmap)
{
byte[] bytearray = null;
Stream smarket = bitmap.StreamSource;
if (smarket != null && smarket.Length > 0)
{
//设置当前位置
smarket.Position = 0;
using (BinaryReader br = new BinaryReader(smarket))
{
bytearray = br.ReadBytes((int)smarket.Length);
}
}
//byte[] bytearray = null;
//Stream smarket = bitmap.StreamSource;
//if (smarket != null && smarket.Length > 0)
//{
// //设置当前位置
// smarket.Position = 0;
// using (BinaryReader br = new BinaryReader(smarket))
// {
// bytearray = br.ReadBytes((int)smarket.Length);
// }
//}
Stream stream = bitmap.StreamSource;
byte[] bytearray = new byte[stream.Length];
stream.Seek(0, SeekOrigin.Begin);
stream.Read(bytearray, 0, bytearray.Length);
return Convert.ToBase64String(bytearray);
}
public static BitmapImage ToBitmapImage(this string base64String, int width = 0, int height =0)
public static BitmapImage ToBitmapImage(this string base64String, int width = 0, int height = 0)
{
if (string.IsNullOrEmpty(base64String))
return null;
@@ -233,5 +239,34 @@ namespace AIStudio.Wpf.DiagramDesigner
return null;
}
}
public static BitmapImage ToBitmapImage(this System.Drawing.Bitmap ImageOriginal, int width = 0, int height = 0)
{
System.Drawing.Bitmap ImageOriginalBase = new System.Drawing.Bitmap(ImageOriginal);
BitmapImage bitmapImage = new BitmapImage() { DecodePixelWidth = width, DecodePixelHeight = height };
System.IO.MemoryStream ms = new System.IO.MemoryStream();
ImageOriginalBase.Save(ms, System.Drawing.Imaging.ImageFormat.Png);
bitmapImage.BeginInit();
bitmapImage.StreamSource = ms;
bitmapImage.CacheOption = BitmapCacheOption.OnLoad;
bitmapImage.EndInit();
bitmapImage.Freeze();
return bitmapImage;
}
public static BitmapImage ToBitmapImage(this byte[] byteArray, int width = 0, int height = 0)
{
BitmapImage bitmapImage = new BitmapImage() { DecodePixelWidth = width, DecodePixelHeight = height };
System.IO.MemoryStream ms = new System.IO.MemoryStream();
bitmapImage.BeginInit();
bitmapImage.StreamSource = ms;
bitmapImage.CacheOption = BitmapCacheOption.OnLoad;
bitmapImage.EndInit();
bitmapImage.Freeze();
return bitmapImage;
}
}
}