@@ -15,165 +15,122 @@ public class TheToBitmapMethod
15
15
{
16
16
[ Fact ]
17
17
public void ShouldThrowExceptionWhenImageFormatIsExif ( )
18
- {
19
- AssertUnsupportedImageFormat ( ImageFormat . Exif ) ;
20
- }
18
+ => AssertUnsupportedImageFormat ( ImageFormat . Exif ) ;
21
19
22
20
[ Fact ]
23
21
public void ShouldThrowExceptionWhenImageFormatIsEmf ( )
24
- {
25
- AssertUnsupportedImageFormat ( ImageFormat . Emf ) ;
26
- }
22
+ => AssertUnsupportedImageFormat ( ImageFormat . Emf ) ;
27
23
28
24
[ Fact ]
29
25
public void ShouldThrowExceptionWhenImageFormatIsWmf ( )
30
- {
31
- AssertUnsupportedImageFormat ( ImageFormat . Wmf ) ;
32
- }
26
+ => AssertUnsupportedImageFormat ( ImageFormat . Wmf ) ;
33
27
34
28
[ Fact ]
35
29
public void ShouldReturnBitmapWhenFormatIsBmp ( )
36
- {
37
- AssertSupportedImageFormat ( ImageFormat . Bmp ) ;
38
- }
30
+ => AssertSupportedImageFormat ( ImageFormat . Bmp ) ;
39
31
40
32
[ Fact ]
41
33
public void ShouldReturnBitmapWhenFormatIsGif ( )
42
- {
43
- AssertSupportedImageFormat ( ImageFormat . Gif ) ;
44
- }
34
+ => AssertSupportedImageFormat ( ImageFormat . Gif ) ;
45
35
46
36
[ Fact ]
47
37
public void ShouldReturnBitmapWhenFormatIsIcon ( )
48
- {
49
- AssertSupportedImageFormat ( ImageFormat . Icon ) ;
50
- }
38
+ => AssertSupportedImageFormat ( ImageFormat . Icon ) ;
51
39
52
40
[ Fact ]
53
41
public void ShouldReturnBitmapWhenFormatIsJpeg ( )
54
- {
55
- AssertSupportedImageFormat ( ImageFormat . Jpeg ) ;
56
- }
42
+ => AssertSupportedImageFormat ( ImageFormat . Jpeg ) ;
57
43
58
44
[ Fact ]
59
45
public void ShouldReturnBitmapWhenFormatIsPng ( )
60
- {
61
- AssertSupportedImageFormat ( ImageFormat . Png ) ;
62
- }
46
+ => AssertSupportedImageFormat ( ImageFormat . Png ) ;
63
47
64
48
[ Fact ]
65
49
public void ShouldReturnBitmapWhenFormatIsTiff ( )
66
- {
67
- AssertSupportedImageFormat ( ImageFormat . Tiff ) ;
68
- }
50
+ => AssertSupportedImageFormat ( ImageFormat . Tiff ) ;
69
51
70
52
[ Fact ]
71
53
public void ShouldChangeTheColorSpaceToSrgb ( )
72
54
{
73
- using ( var image = new MagickImage ( MagickColors . Red , 1 , 1 ) )
74
- {
75
- image . ColorSpace = ColorSpace . YCbCr ;
55
+ using var image = new MagickImage ( MagickColors . Red , 1 , 1 ) ;
56
+ image . ColorSpace = ColorSpace . YCbCr ;
76
57
77
- using ( var bitmap = image . ToBitmap ( ) )
78
- {
79
- ColorAssert . Equal ( MagickColors . Red , ToMagickColor ( bitmap . GetPixel ( 0 , 0 ) ) ) ;
80
- }
58
+ using var bitmap = image . ToBitmap ( ) ;
59
+ ColorAssert . Equal ( MagickColors . Red , ToMagickColor ( bitmap . GetPixel ( 0 , 0 ) ) ) ;
81
60
82
- Assert . Equal ( ColorSpace . YCbCr , image . ColorSpace ) ;
83
- }
61
+ Assert . Equal ( ColorSpace . YCbCr , image . ColorSpace ) ;
84
62
}
85
63
86
64
[ Fact ]
87
65
public void ShouldBeAbleToConvertGrayImage ( )
88
66
{
89
- using ( var image = new MagickImage ( MagickColors . Magenta , 5 , 1 ) )
90
- {
91
- image . Extent ( 5 , 2 , MagickColors . Honeydew ) ;
67
+ using var image = new MagickImage ( MagickColors . Magenta , 5 , 1 ) ;
68
+ image . Extent ( 5 , 2 , MagickColors . Honeydew ) ;
92
69
93
- image . ColorType = ColorType . Bilevel ;
94
- image . ClassType = ClassType . Direct ;
70
+ image . ColorType = ColorType . Bilevel ;
71
+ image . ClassType = ClassType . Direct ;
95
72
96
- Assert . Equal ( ColorSpace . Gray , image . ColorSpace ) ;
73
+ Assert . Equal ( ColorSpace . Gray , image . ColorSpace ) ;
97
74
98
- using ( var bitmap = image . ToBitmap ( ) )
99
- {
100
- for ( var i = 0 ; i < image . Width ; i ++ )
101
- ColorAssert . Equal ( MagickColors . Black , ToMagickColor ( bitmap . GetPixel ( i , 0 ) ) ) ;
75
+ using var bitmap = image . ToBitmap ( ) ;
76
+ for ( var i = 0 ; i < image . Width ; i ++ )
77
+ ColorAssert . Equal ( MagickColors . Black , ToMagickColor ( bitmap . GetPixel ( i , 0 ) ) ) ;
102
78
103
- for ( var i = 0 ; i < image . Width ; i ++ )
104
- ColorAssert . Equal ( MagickColors . White , ToMagickColor ( bitmap . GetPixel ( i , 1 ) ) ) ;
105
- }
106
- }
79
+ for ( var i = 0 ; i < image . Width ; i ++ )
80
+ ColorAssert . Equal ( MagickColors . White , ToMagickColor ( bitmap . GetPixel ( i , 1 ) ) ) ;
107
81
}
108
82
109
83
[ Fact ]
110
84
public void ShouldBeAbleToConvertRgbImage ( )
111
85
{
112
- using ( var image = new MagickImage ( MagickColors . Magenta , 5 , 1 ) )
113
- {
114
- using ( var bitmap = image . ToBitmap ( ) )
115
- {
116
- for ( var i = 0 ; i < image . Width ; i ++ )
117
- ColorAssert . Equal ( MagickColors . Magenta , ToMagickColor ( bitmap . GetPixel ( i , 0 ) ) ) ;
118
- }
119
- }
86
+ using var image = new MagickImage ( MagickColors . Magenta , 5 , 1 ) ;
87
+ using var bitmap = image . ToBitmap ( ) ;
88
+ for ( var i = 0 ; i < image . Width ; i ++ )
89
+ ColorAssert . Equal ( MagickColors . Magenta , ToMagickColor ( bitmap . GetPixel ( i , 0 ) ) ) ;
120
90
}
121
91
122
92
[ Fact ]
123
93
public void ShouldBeAbleToConvertRgbaImage ( )
124
94
{
125
- using ( var image = new MagickImage ( MagickColors . Magenta , 5 , 1 ) )
126
- {
127
- image . Alpha ( AlphaOption . On ) ;
128
-
129
- using ( var bitmap = image . ToBitmap ( ) )
130
- {
131
- var color = MagickColors . Magenta ;
132
- color . A = Quantum . Max ;
133
-
134
- for ( var i = 0 ; i < image . Width ; i ++ )
135
- ColorAssert . Equal ( color , ToMagickColor ( bitmap . GetPixel ( i , 0 ) ) ) ;
136
- }
137
- }
95
+ using var image = new MagickImage ( MagickColors . Magenta , 5 , 1 ) ;
96
+ image . Alpha ( AlphaOption . On ) ;
97
+
98
+ var color = MagickColors . Magenta ;
99
+ color . A = Quantum . Max ;
100
+
101
+ using var bitmap = image . ToBitmap ( ) ;
102
+ for ( var i = 0 ; i < image . Width ; i ++ )
103
+ ColorAssert . Equal ( color , ToMagickColor ( bitmap . GetPixel ( i , 0 ) ) ) ;
138
104
}
139
105
140
106
[ Fact ]
141
107
public void ShouldThrowExceptionWhenImageFormatIsNull ( )
142
108
{
143
- using ( var image = new MagickImage ( MagickColors . Red , 1 , 1 ) )
144
- {
145
- Assert . Throws < ArgumentNullException > ( "imageFormat" , ( ) => image . ToBitmapWithDensity ( null ) ) ;
146
- }
109
+ using var image = new MagickImage ( MagickColors . Red , 1 , 1 ) ;
110
+
111
+ Assert . Throws < ArgumentNullException > ( "imageFormat" , ( ) => image . ToBitmapWithDensity ( null ) ) ;
147
112
}
148
113
149
114
private void AssertUnsupportedImageFormat ( ImageFormat imageFormat )
150
115
{
151
- using ( var image = new MagickImage ( MagickColors . Red , 10 , 10 ) )
152
- {
153
- Assert . Throws < NotSupportedException > ( ( ) =>
154
- {
155
- image . ToBitmap ( imageFormat ) ;
156
- } ) ;
157
- }
116
+ using var image = new MagickImage ( MagickColors . Red , 10 , 10 ) ;
117
+
118
+ Assert . Throws < NotSupportedException > ( ( ) => image . ToBitmap ( imageFormat ) ) ;
158
119
}
159
120
160
121
private void AssertSupportedImageFormat ( ImageFormat imageFormat )
161
122
{
162
- using ( var image = new MagickImage ( MagickColors . Red , 10 , 10 ) )
163
- {
164
- using ( var bitmap = image . ToBitmap ( imageFormat ) )
165
- {
166
- Assert . Equal ( imageFormat , bitmap . RawFormat ) ;
167
-
168
- // Cannot test JPEG due to rounding issues.
169
- if ( imageFormat != ImageFormat . Jpeg )
170
- {
171
- ColorAssert . Equal ( MagickColors . Red , ToMagickColor ( bitmap . GetPixel ( 0 , 0 ) ) ) ;
172
- ColorAssert . Equal ( MagickColors . Red , ToMagickColor ( bitmap . GetPixel ( 5 , 5 ) ) ) ;
173
- ColorAssert . Equal ( MagickColors . Red , ToMagickColor ( bitmap . GetPixel ( 9 , 9 ) ) ) ;
174
- }
175
- }
176
- }
123
+ using var image = new MagickImage ( MagickColors . Red , 10 , 10 ) ;
124
+ using var bitmap = image . ToBitmap ( imageFormat ) ;
125
+ Assert . Equal ( imageFormat , bitmap . RawFormat ) ;
126
+
127
+ // Cannot test JPEG due to rounding issues.
128
+ if ( imageFormat == ImageFormat . Jpeg )
129
+ return ;
130
+
131
+ ColorAssert . Equal ( MagickColors . Red , ToMagickColor ( bitmap . GetPixel ( 0 , 0 ) ) ) ;
132
+ ColorAssert . Equal ( MagickColors . Red , ToMagickColor ( bitmap . GetPixel ( 5 , 5 ) ) ) ;
133
+ ColorAssert . Equal ( MagickColors . Red , ToMagickColor ( bitmap . GetPixel ( 9 , 9 ) ) ) ;
177
134
}
178
135
179
136
private MagickColor ToMagickColor ( Color color )
0 commit comments