blob: bc38051fc7bb4f6be1d61f87b71881668afa514b (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
|
/*
* GNU AFFERO GENERAL PUBLIC LICENSE
* Version 3, 19 November 2007
* Copyright (C) 2007 Free Software Foundation, Inc. <https://fsf.org/>
* Everyone is permitted to copy and distribute verbatim copies
* of this license document, but changing it is not allowed.
*/
using System.IO;
using Emgu.CV;
using Emgu.CV.Structure;
using SixLabors.ImageSharp;
using SixLabors.ImageSharp.PixelFormats;
using UVtools.Parser;
namespace UVtools.GUI.Extensions
{
public static class ImageSharpExtensions
{
public static System.Drawing.Bitmap ToBitmap(this Image image)
{
using (var memoryStream = new MemoryStream())
{
//var imageEncoder = image.GetConfiguration().ImageFormatsManager.FindEncoder(SixLabors.ImageSharp.Formats.Bmp.BmpFormat.Instance);
Helpers.BmpEncoder.SupportTransparency = true;
image.Save(memoryStream, Helpers.BmpEncoder);
memoryStream.Seek(0, SeekOrigin.Begin);
return new System.Drawing.Bitmap(memoryStream);
}
}
public static Image<Gray, byte> ToEmguImage(this Image<L8> image)
{
return
new Image<Gray, byte>(image.Width, image.Height)
{
Bytes = Helpers.ImageL8ToBytes(image)
};
}
/*public static Image<TPixel> ToImageSharpImage<TPixel>(this System.Drawing.Bitmap bitmap) where TPixel : struct, IPixel<TPixel>
{
using (var memoryStream = new MemoryStream())
{
bitmap.Save(memoryStream, System.Drawing.Imaging.ImageFormat.Png);
memoryStream.Seek(0, SeekOrigin.Begin);
return Image.Load<TPixel>(memoryStream);
}
}*/
}
}
|