@@ -169,17 +169,18 @@ private static ImageSource DecodeWithTiff(Stream stream, long size)
169169 if ( tiff == null )
170170 return new ImageSource ( null , 0 ) ;
171171
172+ // Currently only supports image when its `BITSPERSAMPLE` is one in [1,2,4,8,16]
172173 var width = tiff . GetField ( TiffTag . IMAGEWIDTH ) [ 0 ] . ToInt ( ) ;
173174 var height = tiff . GetField ( TiffTag . IMAGELENGTH ) [ 0 ] . ToInt ( ) ;
174175 var pixels = new int [ width * height ] ;
175-
176- // Currently only supports image when its `BITSPERSAMPLE` is one in [1,2,4,8,16]
177176 tiff . ReadRGBAImageOriented ( width , height , pixels , Orientation . TOPLEFT ) ;
178177
179- var ptr = Marshal . UnsafeAddrOfPinnedArrayElement ( pixels , 0 ) ;
180178 var pixelSize = new PixelSize ( width , height ) ;
181179 var dpi = new Vector ( 96 , 96 ) ;
182- var bitmap = new Bitmap ( PixelFormats . Rgba8888 , AlphaFormat . Unpremul , ptr , pixelSize , dpi , width * 4 ) ;
180+ var bitmap = new WriteableBitmap ( pixelSize , dpi , PixelFormats . Rgba8888 , AlphaFormat . Unpremul ) ;
181+
182+ using var frameBuffer = bitmap . Lock ( ) ;
183+ Marshal . Copy ( pixels , 0 , frameBuffer . Address , pixels . Length ) ;
183184 return new ImageSource ( bitmap , size ) ;
184185 }
185186 }
0 commit comments