markus / ImageComparer / Markus.ImageComparer / PixelFormatsConverter.cs @ b2c6901f
이력 | 보기 | 이력해설 | 다운로드 (7.81 KB)
1 | 6b6e937c | taeseongkim | using System; |
---|---|---|---|
2 | using System.Collections.Generic; |
||
3 | using System.Linq; |
||
4 | using System.Text; |
||
5 | using System.Threading.Tasks; |
||
6 | |||
7 | namespace Markus.Image |
||
8 | { |
||
9 | |||
10 | public static class PixelFormatConverterExtensions |
||
11 | { |
||
12 | /// <summary> |
||
13 | /// Convert from System.Drawing.Imaging.PixelFormat to System.Windows.Media.PixelFormat |
||
14 | /// </summary> |
||
15 | /// <param name="pixelFormat"></param> |
||
16 | /// <exception cref="NotSupportedException">Convertion is not available</exception> |
||
17 | /// <returns></returns> |
||
18 | public static System.Windows.Media.PixelFormat Convert(this System.Drawing.Imaging.PixelFormat pixelFormat) |
||
19 | { |
||
20 | if (pixelFormat == System.Drawing.Imaging.PixelFormat.Format16bppGrayScale) |
||
21 | return System.Windows.Media.PixelFormats.Gray16; |
||
22 | if (pixelFormat == System.Drawing.Imaging.PixelFormat.Format16bppRgb555) |
||
23 | return System.Windows.Media.PixelFormats.Bgr555; |
||
24 | if (pixelFormat == System.Drawing.Imaging.PixelFormat.Format16bppRgb565) |
||
25 | return System.Windows.Media.PixelFormats.Bgr565; |
||
26 | |||
27 | if (pixelFormat == System.Drawing.Imaging.PixelFormat.Indexed) |
||
28 | return System.Windows.Media.PixelFormats.Bgr101010; |
||
29 | if (pixelFormat == System.Drawing.Imaging.PixelFormat.Format1bppIndexed) |
||
30 | return System.Windows.Media.PixelFormats.Indexed1; |
||
31 | if (pixelFormat == System.Drawing.Imaging.PixelFormat.Format4bppIndexed) |
||
32 | return System.Windows.Media.PixelFormats.Indexed4; |
||
33 | if (pixelFormat == System.Drawing.Imaging.PixelFormat.Format8bppIndexed) |
||
34 | return System.Windows.Media.PixelFormats.Indexed8; |
||
35 | |||
36 | //if (pixelFormat == System.Drawing.Imaging.PixelFormat.Format16bppArgb1555) |
||
37 | // return System.Windows.Media.PixelFormats.Bgr101010; |
||
38 | |||
39 | if (pixelFormat == System.Drawing.Imaging.PixelFormat.Format24bppRgb) |
||
40 | return System.Windows.Media.PixelFormats.Bgr24; |
||
41 | |||
42 | if (pixelFormat == System.Drawing.Imaging.PixelFormat.Format32bppArgb) |
||
43 | return System.Windows.Media.PixelFormats.Bgr32; |
||
44 | if (pixelFormat == System.Drawing.Imaging.PixelFormat.Format32bppPArgb) |
||
45 | return System.Windows.Media.PixelFormats.Pbgra32; |
||
46 | if (pixelFormat == System.Drawing.Imaging.PixelFormat.Format32bppRgb) |
||
47 | return System.Windows.Media.PixelFormats.Bgr32; |
||
48 | |||
49 | if (pixelFormat == System.Drawing.Imaging.PixelFormat.Format48bppRgb) |
||
50 | return System.Windows.Media.PixelFormats.Rgb48; |
||
51 | |||
52 | if (pixelFormat == System.Drawing.Imaging.PixelFormat.Format64bppArgb) |
||
53 | return System.Windows.Media.PixelFormats.Prgba64; |
||
54 | |||
55 | // TODO : |
||
56 | //if (pixelFormat == System.Drawing.Imaging.PixelFormat.Alpha) |
||
57 | // return System.Windows.Media.PixelFormats.; |
||
58 | //if (pixelFormat == System.Drawing.Imaging.PixelFormat.Canonical) |
||
59 | // return System.Windows.Media.PixelFormats.; |
||
60 | //if (pixelFormat == System.Drawing.Imaging.PixelFormat.DontCare) |
||
61 | // return System.Windows.Media.PixelFormats.; |
||
62 | //if (pixelFormat == System.Drawing.Imaging.PixelFormat.Extended) |
||
63 | // return System.Windows.Media.PixelFormats.; |
||
64 | //if (pixelFormat == System.Drawing.Imaging.PixelFormat.Gdi) |
||
65 | // return System.Windows.Media.PixelFormats.Default; |
||
66 | //if (pixelFormat == System.Drawing.Imaging.PixelFormat.Max) |
||
67 | // return System.Windows.Media.PixelFormats.Default; |
||
68 | //if (pixelFormat == System.Drawing.Imaging.PixelFormat.PAlpha) |
||
69 | // return System.Windows.Media.PixelFormats.Default; |
||
70 | |||
71 | if (pixelFormat == System.Drawing.Imaging.PixelFormat.Undefined) |
||
72 | return System.Windows.Media.PixelFormats.Default; |
||
73 | |||
74 | throw new NotSupportedException("Convertion not supported with " + pixelFormat.ToString()); |
||
75 | } |
||
76 | |||
77 | /// <summary> |
||
78 | /// Convert from System.Windows.Media.PixelFormat to System.Drawing.Imaging.PixelFormat |
||
79 | /// </summary> |
||
80 | /// <param name="pixelFormat"></param> |
||
81 | /// <exception cref="NotSupportedException">Convertion is not available</exception> |
||
82 | /// <returns></returns> |
||
83 | public static System.Drawing.Imaging.PixelFormat Convert(this System.Windows.Media.PixelFormat pixelFormat) |
||
84 | { |
||
85 | if (pixelFormat == System.Windows.Media.PixelFormats.Gray16) |
||
86 | return System.Drawing.Imaging.PixelFormat.Format16bppGrayScale; |
||
87 | if (pixelFormat == System.Windows.Media.PixelFormats.Bgr555) |
||
88 | return System.Drawing.Imaging.PixelFormat.Format16bppRgb555; |
||
89 | if (pixelFormat == System.Windows.Media.PixelFormats.Bgr565) |
||
90 | return System.Drawing.Imaging.PixelFormat.Format16bppRgb565; |
||
91 | |||
92 | if (pixelFormat == System.Windows.Media.PixelFormats.Bgr101010) |
||
93 | return System.Drawing.Imaging.PixelFormat.Indexed; |
||
94 | if (pixelFormat == System.Windows.Media.PixelFormats.Indexed1) |
||
95 | return System.Drawing.Imaging.PixelFormat.Format1bppIndexed; |
||
96 | if (pixelFormat == System.Windows.Media.PixelFormats.Indexed4) |
||
97 | return System.Drawing.Imaging.PixelFormat.Format4bppIndexed; |
||
98 | if (pixelFormat == System.Windows.Media.PixelFormats.Indexed8) |
||
99 | return System.Drawing.Imaging.PixelFormat.Format8bppIndexed; |
||
100 | |||
101 | //if (pixelFormat == System.Drawing.Imaging.PixelFormat.Format16bppArgb1555) |
||
102 | // return System.Windows.Media.PixelFormats.Bgr101010; |
||
103 | |||
104 | if (pixelFormat == System.Windows.Media.PixelFormats.Bgr24) |
||
105 | return System.Drawing.Imaging.PixelFormat.Format24bppRgb; |
||
106 | |||
107 | if (pixelFormat == System.Windows.Media.PixelFormats.Bgr32) |
||
108 | return System.Drawing.Imaging.PixelFormat.Format32bppArgb; |
||
109 | if (pixelFormat == System.Windows.Media.PixelFormats.Pbgra32) |
||
110 | return System.Drawing.Imaging.PixelFormat.Format32bppPArgb; |
||
111 | if (pixelFormat == System.Windows.Media.PixelFormats.Bgr32) |
||
112 | return System.Drawing.Imaging.PixelFormat.Format32bppRgb; |
||
113 | |||
114 | if (pixelFormat == System.Windows.Media.PixelFormats.Rgb48) |
||
115 | return System.Drawing.Imaging.PixelFormat.Format48bppRgb; |
||
116 | |||
117 | if (pixelFormat == System.Windows.Media.PixelFormats.Prgba64) |
||
118 | return System.Drawing.Imaging.PixelFormat.Format64bppArgb; |
||
119 | |||
120 | // TODO : |
||
121 | //if (pixelFormat == System.Windows.Media.PixelFormats.) |
||
122 | // return System.Drawing.Imaging.PixelFormat.Alpha; |
||
123 | //if (pixelFormat == System.Windows.Media.PixelFormats.) |
||
124 | // return System.Drawing.Imaging.PixelFormat.Canonical; |
||
125 | //if (pixelFormat == System.Windows.Media.PixelFormats.) |
||
126 | // return System.Drawing.Imaging.PixelFormat.DontCare; |
||
127 | // return System.Windows.Media.PixelFormats.; |
||
128 | //if (pixelFormat == System.Windows.Media.PixelFormats.) |
||
129 | // return System.Drawing.Imaging.PixelFormat.Extended; |
||
130 | //if (pixelFormat == System.Windows.Media.PixelFormats.) |
||
131 | // return System.Drawing.Imaging.PixelFormat.Gdi; |
||
132 | //if (pixelFormat == System.Windows.Media.PixelFormats.) |
||
133 | // return System.Drawing.Imaging.PixelFormat.Max; |
||
134 | //if (pixelFormat == System.Windows.Media.PixelFormats.) |
||
135 | // return System.Drawing.Imaging.PixelFormat.PAlpha; |
||
136 | //if (pixelFormat == System.Windows.Media.PixelFormats.) |
||
137 | // return System.Drawing.Imaging.PixelFormat.Undefined; |
||
138 | |||
139 | if (pixelFormat == System.Windows.Media.PixelFormats.Default) |
||
140 | return System.Drawing.Imaging.PixelFormat.Undefined; |
||
141 | |||
142 | throw new NotSupportedException("Convertion not supported with " + pixelFormat.ToString()); |
||
143 | } |
||
144 | } |
||
145 | } |