@@ -134,7 +134,7 @@ int stride
134134 ArgumentNullException . ThrowIfNull ( pixels ) ;
135135
136136 if ( pixels . Rank != 1 )
137- throw new ArgumentException ( SR . Collection_BadRank , " pixels" ) ;
137+ throw new ArgumentException ( SR . Collection_BadRank , nameof ( pixels ) ) ;
138138
139139 int elementSize = - 1 ;
140140
@@ -152,55 +152,8 @@ int stride
152152
153153 int destBufferSize = elementSize * pixels . Length ;
154154
155- if ( pixels is byte [ ] )
156- {
157- fixed( void * pixelArray = ( byte [ ] ) pixels )
158- InitFromMemoryPtr ( pixelWidth , pixelHeight , dpiX , dpiY ,
159- pixelFormat , palette ,
160- ( IntPtr ) pixelArray , destBufferSize , stride ) ;
161- }
162- else if ( pixels is short [ ] )
163- {
164- fixed( void * pixelArray = ( short [ ] ) pixels )
165- InitFromMemoryPtr ( pixelWidth , pixelHeight , dpiX , dpiY ,
166- pixelFormat , palette ,
167- ( IntPtr ) pixelArray , destBufferSize , stride ) ;
168- }
169- else if ( pixels is ushort [ ] )
170- {
171- fixed( void * pixelArray = ( ushort [ ] ) pixels )
172- InitFromMemoryPtr ( pixelWidth , pixelHeight , dpiX , dpiY ,
173- pixelFormat , palette ,
174- ( IntPtr ) pixelArray , destBufferSize , stride ) ;
175- }
176- else if ( pixels is int [ ] )
177- {
178- fixed( void * pixelArray = ( int [ ] ) pixels )
179- InitFromMemoryPtr ( pixelWidth , pixelHeight , dpiX , dpiY ,
180- pixelFormat , palette ,
181- ( IntPtr ) pixelArray , destBufferSize , stride ) ;
182- }
183- else if ( pixels is uint [ ] )
184- {
185- fixed( void * pixelArray = ( uint [ ] ) pixels )
186- InitFromMemoryPtr ( pixelWidth , pixelHeight , dpiX , dpiY ,
187- pixelFormat , palette ,
188- ( IntPtr ) pixelArray , destBufferSize , stride ) ;
189- }
190- else if ( pixels is float [ ] )
191- {
192- fixed( void * pixelArray = ( float [ ] ) pixels )
193- InitFromMemoryPtr ( pixelWidth , pixelHeight , dpiX , dpiY ,
194- pixelFormat , palette ,
195- ( IntPtr ) pixelArray , destBufferSize , stride ) ;
196- }
197- else if ( pixels is double [ ] )
198- {
199- fixed( void * pixelArray = ( double [ ] ) pixels )
200- InitFromMemoryPtr ( pixelWidth , pixelHeight , dpiX , dpiY ,
201- pixelFormat , palette ,
202- ( IntPtr ) pixelArray , destBufferSize , stride ) ;
203- }
155+ fixed ( byte * pixelArray = & MemoryMarshal . GetArrayDataReference ( pixels ) )
156+ InitFromMemoryPtr ( pixelWidth , pixelHeight , dpiX , dpiY , pixelFormat , palette , ( nint ) pixelArray , destBufferSize , stride ) ;
204157 }
205158
206159 /// <summary>
0 commit comments