markus / Markus.ImageComparer / Converter.cs @ master
이력 | 보기 | 이력해설 | 다운로드 (1.37 KB)
1 |
using System; |
---|---|
2 |
using System.Collections.Generic; |
3 |
using System.Drawing; |
4 |
using System.IO; |
5 |
using System.Linq; |
6 |
using System.Text; |
7 |
using System.Threading.Tasks; |
8 |
using System.Windows.Media.Imaging; |
9 |
|
10 |
namespace Markus.Image |
11 |
{ |
12 |
public static class Converter |
13 |
{ |
14 |
public static Bitmap ConvertBitmapFrameToBitmap(BitmapSource bitmapSource) |
15 |
{ |
16 |
using (MemoryStream outStream = new MemoryStream()) |
17 |
{ |
18 |
BitmapEncoder enc = new BmpBitmapEncoder(); |
19 |
enc.Frames.Add(BitmapFrame.Create(bitmapSource,null,null,null)); |
20 |
enc.Save(outStream); |
21 |
outStream.Seek(0, SeekOrigin.Begin); |
22 |
using (Bitmap bitmap = new Bitmap(outStream)) |
23 |
{ |
24 |
return new Bitmap(bitmap); // 새로운 Bitmap 객체를 반환하여 원본을 해제 |
25 |
} |
26 |
} |
27 |
} |
28 |
|
29 |
public static OpenCvSharp.Mat ConvertBitmapFrameToMat(BitmapSource bitmapSource) |
30 |
{ |
31 |
using (MemoryStream outStream = new MemoryStream()) |
32 |
{ |
33 |
BitmapEncoder enc = new BmpBitmapEncoder(); |
34 |
enc.Frames.Add(BitmapFrame.Create(bitmapSource, null, null, null)); |
35 |
enc.Save(outStream); |
36 |
|
37 |
return OpenCvSharp.Mat.FromImageData(outStream.ToArray(), OpenCvSharp.ImreadModes.Color); |
38 |
} |
39 |
} |
40 |
} |
41 |
} |