Skip to content

Commit 13c40da

Browse files
committed
refactor: use WriteableBitmap instead of Bitmap for .tif images
Signed-off-by: leo <[email protected]>
1 parent fbb9f78 commit 13c40da

File tree

1 file changed

+5
-4
lines changed

1 file changed

+5
-4
lines changed

‎src/ViewModels/ImageSource.cs‎

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -169,17 +169,18 @@ private static ImageSource DecodeWithTiff(Stream stream, long size)
169169
if(tiff==null)
170170
returnnewImageSource(null,0);
171171

172+
// Currently only supports image when its `BITSPERSAMPLE` is one in [1,2,4,8,16]
172173
varwidth=tiff.GetField(TiffTag.IMAGEWIDTH)[0].ToInt();
173174
varheight=tiff.GetField(TiffTag.IMAGELENGTH)[0].ToInt();
174175
varpixels=newint[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-
varptr=Marshal.UnsafeAddrOfPinnedArrayElement(pixels,0);
180178
varpixelSize=newPixelSize(width,height);
181179
vardpi=newVector(96,96);
182-
varbitmap=newBitmap(PixelFormats.Rgba8888,AlphaFormat.Unpremul,ptr,pixelSize,dpi,width*4);
180+
varbitmap=newWriteableBitmap(pixelSize,dpi,PixelFormats.Rgba8888,AlphaFormat.Unpremul);
181+
182+
usingvarframeBuffer=bitmap.Lock();
183+
Marshal.Copy(pixels,0,frameBuffer.Address,pixels.Length);
183184
returnnewImageSource(bitmap,size);
184185
}
185186
}

0 commit comments

Comments
(0)