File tree Expand file tree Collapse file tree 1 file changed +19
-11
lines changed
src/ImageSharp/Formats/Webp/Lossy Expand file tree Collapse file tree 1 file changed +19
-11
lines changed Original file line number Diff line number Diff line change @@ -349,10 +349,11 @@ public void Encode<TPixel>(Image<TPixel> image, Stream stream)
349
349
int alphaDataSize = 0 ;
350
350
bool alphaCompressionSucceeded = false ;
351
351
Span < byte > alphaData = Span < byte > . Empty ;
352
+ IMemoryOwner < byte > encodedAlphaData = null ;
352
353
if ( hasAlpha )
353
354
{
354
355
// TODO: This can potentially run in an separate task.
355
- using IMemoryOwner < byte > encodedAlphaData = AlphaEncoder . EncodeAlpha (
356
+ encodedAlphaData = AlphaEncoder . EncodeAlpha (
356
357
image ,
357
358
this . configuration ,
358
359
this . memoryAllocator ,
@@ -405,16 +406,23 @@ public void Encode<TPixel>(Image<TPixel> image, Stream stream)
405
406
ExifProfile exifProfile = this . skipMetadata ? null : metadata . ExifProfile ;
406
407
XmpProfile xmpProfile = this . skipMetadata ? null : metadata . XmpProfile ;
407
408
408
- this . bitWriter . WriteEncodedImageToStream (
409
- stream ,
410
- exifProfile ,
411
- xmpProfile ,
412
- metadata . IccProfile ,
413
- ( uint ) width ,
414
- ( uint ) height ,
415
- hasAlpha ,
416
- alphaData [ ..alphaDataSize ] ,
417
- this . alphaCompression && alphaCompressionSucceeded ) ;
409
+ try
410
+ {
411
+ this . bitWriter . WriteEncodedImageToStream (
412
+ stream ,
413
+ exifProfile ,
414
+ xmpProfile ,
415
+ metadata . IccProfile ,
416
+ ( uint ) width ,
417
+ ( uint ) height ,
418
+ hasAlpha ,
419
+ alphaData [ ..alphaDataSize ] ,
420
+ this . alphaCompression && alphaCompressionSucceeded ) ;
421
+ }
422
+ finally
423
+ {
424
+ encodedAlphaData ? . Dispose ( ) ;
425
+ }
418
426
}
419
427
420
428
/// <inheritdoc/>
You can’t perform that action at this time.
0 commit comments