@@ -169,17 +169,18 @@ private static ImageSource DecodeWithTiff(Stream stream, long size)
169169if ( tiff == null )
170170return new ImageSource ( null , 0 ) ;
171171
172+ // Currently only supports image when its `BITSPERSAMPLE` is one in [1,2,4,8,16]
172173var width = tiff . GetField ( TiffTag . IMAGEWIDTH ) [ 0 ] . ToInt ( ) ;
173174var height = tiff . GetField ( TiffTag . IMAGELENGTH ) [ 0 ] . ToInt ( ) ;
174175var pixels = new int [ width * height ] ;
175-
176- // Currently only supports image when its `BITSPERSAMPLE` is one in [1,2,4,8,16]
177176tiff . ReadRGBAImageOriented ( width , height , pixels , Orientation . TOPLEFT ) ;
178177
179- var ptr = Marshal . UnsafeAddrOfPinnedArrayElement ( pixels , 0 ) ;
180178var pixelSize = new PixelSize ( width , height ) ;
181179var 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 ) ;
183184return new ImageSource ( bitmap , size ) ;
184185}
185186}
0 commit comments