1
1
// Licensed to the .NET Foundation under one or more agreements.
2
2
// The .NET Foundation licenses this file to you under the MIT license.
3
- // See the LICENSE file in the project root for more information.
4
3
5
- using MS . Internal ;
4
+ using System . Runtime . InteropServices ;
6
5
using MS . Win32 . PresentationCore ;
6
+ using MS . Internal ;
7
7
8
8
namespace System . Windows . Media . Imaging
9
9
{
@@ -113,7 +113,7 @@ int stride
113
113
ArgumentNullException . ThrowIfNull ( pixels ) ;
114
114
115
115
if ( pixels . Rank != 1 )
116
- throw new ArgumentException ( SR . Collection_BadRank , " pixels" ) ;
116
+ throw new ArgumentException ( SR . Collection_BadRank , nameof ( pixels ) ) ;
117
117
118
118
int elementSize = - 1 ;
119
119
@@ -131,55 +131,8 @@ int stride
131
131
132
132
int destBufferSize = elementSize * pixels . Length ;
133
133
134
- if ( pixels is byte [ ] )
135
- {
136
- fixed( void * pixelArray = ( byte [ ] ) pixels )
137
- InitFromMemoryPtr ( pixelWidth , pixelHeight , dpiX , dpiY ,
138
- pixelFormat , palette ,
139
- ( IntPtr ) pixelArray , destBufferSize , stride ) ;
140
- }
141
- else if ( pixels is short [ ] )
142
- {
143
- fixed( void * pixelArray = ( short [ ] ) pixels )
144
- InitFromMemoryPtr ( pixelWidth , pixelHeight , dpiX , dpiY ,
145
- pixelFormat , palette ,
146
- ( IntPtr ) pixelArray , destBufferSize , stride ) ;
147
- }
148
- else if ( pixels is ushort [ ] )
149
- {
150
- fixed( void * pixelArray = ( ushort [ ] ) pixels )
151
- InitFromMemoryPtr ( pixelWidth , pixelHeight , dpiX , dpiY ,
152
- pixelFormat , palette ,
153
- ( IntPtr ) pixelArray , destBufferSize , stride ) ;
154
- }
155
- else if ( pixels is int [ ] )
156
- {
157
- fixed( void * pixelArray = ( int [ ] ) pixels )
158
- InitFromMemoryPtr ( pixelWidth , pixelHeight , dpiX , dpiY ,
159
- pixelFormat , palette ,
160
- ( IntPtr ) pixelArray , destBufferSize , stride ) ;
161
- }
162
- else if ( pixels is uint [ ] )
163
- {
164
- fixed( void * pixelArray = ( uint [ ] ) pixels )
165
- InitFromMemoryPtr ( pixelWidth , pixelHeight , dpiX , dpiY ,
166
- pixelFormat , palette ,
167
- ( IntPtr ) pixelArray , destBufferSize , stride ) ;
168
- }
169
- else if ( pixels is float [ ] )
170
- {
171
- fixed( void * pixelArray = ( float [ ] ) pixels )
172
- InitFromMemoryPtr ( pixelWidth , pixelHeight , dpiX , dpiY ,
173
- pixelFormat , palette ,
174
- ( IntPtr ) pixelArray , destBufferSize , stride ) ;
175
- }
176
- else if ( pixels is double [ ] )
177
- {
178
- fixed( void * pixelArray = ( double [ ] ) pixels )
179
- InitFromMemoryPtr ( pixelWidth , pixelHeight , dpiX , dpiY ,
180
- pixelFormat , palette ,
181
- ( IntPtr ) pixelArray , destBufferSize , stride ) ;
182
- }
134
+ fixed ( byte * pixelArray = & MemoryMarshal . GetArrayDataReference ( pixels ) )
135
+ InitFromMemoryPtr ( pixelWidth , pixelHeight , dpiX , dpiY , pixelFormat , palette , ( nint ) pixelArray , destBufferSize , stride ) ;
183
136
}
184
137
185
138
/// <summary>
0 commit comments