applying new struckture and working vlc
This commit is contained in:
42
ShadowStream/Modules/ObjecktForJason/BitmapConversions.cs
Normal file
42
ShadowStream/Modules/ObjecktForJason/BitmapConversions.cs
Normal file
@@ -0,0 +1,42 @@
|
||||
|
||||
using System.Drawing;
|
||||
using System.IO;
|
||||
using System.Windows.Media.Imaging;
|
||||
|
||||
namespace ShadowStream.Modules;
|
||||
|
||||
public class BitmapConversions
|
||||
{
|
||||
public static BitmapImage BitmapToBitmapImage(System.Drawing.Bitmap bitmap)
|
||||
{
|
||||
using (var memory = new System.IO.MemoryStream())
|
||||
{
|
||||
bitmap.Save(memory, System.Drawing.Imaging.ImageFormat.Png);
|
||||
memory.Position = 0;
|
||||
|
||||
var bitmapImage = new BitmapImage();
|
||||
bitmapImage.BeginInit();
|
||||
bitmapImage.StreamSource = memory;
|
||||
bitmapImage.CacheOption = BitmapCacheOption.OnLoad;
|
||||
bitmapImage.EndInit();
|
||||
bitmapImage.Freeze(); // Optional: for thread safety
|
||||
|
||||
return bitmapImage;
|
||||
}
|
||||
}
|
||||
public static Bitmap BitmapImageToBitmap(BitmapImage bitmapImage)
|
||||
{
|
||||
using (MemoryStream ms = new MemoryStream())
|
||||
{
|
||||
// Encode BitmapImage to stream (e.g., PNG)
|
||||
BitmapEncoder encoder = new PngBitmapEncoder();
|
||||
encoder.Frames.Add(BitmapFrame.Create(bitmapImage));
|
||||
encoder.Save(ms);
|
||||
|
||||
ms.Seek(0, SeekOrigin.Begin); // Reset stream position
|
||||
|
||||
// Create Bitmap from stream
|
||||
return new Bitmap(ms);
|
||||
}
|
||||
}
|
||||
}
|
@@ -37,14 +37,14 @@ public class Jason_Writer
|
||||
|
||||
|
||||
// Load one list of locJason objects from JSON file with given name
|
||||
public List<locJason> LoadList(string listName)
|
||||
public async Task<List<locJason>> LoadListAsync(string listName)
|
||||
{
|
||||
string filePath = Path.Combine(_folderPath, $"{listName}.json");
|
||||
|
||||
if (!File.Exists(filePath))
|
||||
return new List<locJason>(); // Return empty list if file doesn't exist
|
||||
return new List<locJason>();
|
||||
|
||||
string jsonString = File.ReadAllText(filePath);
|
||||
string jsonString = await File.ReadAllTextAsync(filePath);
|
||||
return JsonConvert.DeserializeObject<List<locJason>>(jsonString) ?? new List<locJason>();
|
||||
}
|
||||
|
||||
|
26
ShadowStream/Modules/ObjecktForJason/JasonToString.cs
Normal file
26
ShadowStream/Modules/ObjecktForJason/JasonToString.cs
Normal file
@@ -0,0 +1,26 @@
|
||||
using System.Drawing;
|
||||
using System.IO;
|
||||
|
||||
namespace ShadowStream.Modules;
|
||||
|
||||
|
||||
public class JasonToString
|
||||
{
|
||||
public Bitmap Base64StringToBitmap(string base64String)
|
||||
{
|
||||
byte[] imageBytes = Convert.FromBase64String(base64String);
|
||||
using (MemoryStream ms = new MemoryStream(imageBytes))
|
||||
{
|
||||
return new Bitmap(ms);
|
||||
}
|
||||
}
|
||||
public string BitmapToBase64String(Bitmap bitmap)
|
||||
{
|
||||
using (MemoryStream ms = new MemoryStream())
|
||||
{
|
||||
bitmap.Save(ms, System.Drawing.Imaging.ImageFormat.Png); // Save as PNG to MemoryStream
|
||||
byte[] imageBytes = ms.ToArray();
|
||||
return Convert.ToBase64String(imageBytes);
|
||||
}
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user