File tree Expand file tree Collapse file tree 1 file changed +18
-1
lines changed
src/ImageSharp/Formats/Png Expand file tree Collapse file tree 1 file changed +18
-1
lines changed Original file line number Diff line number Diff line change @@ -230,7 +230,24 @@ public FormatConnectingMetadata ToFormatConnectingMetadata()
230230 /// <inheritdoc/>
231231 public void AfterImageApply < TPixel > ( Image < TPixel > destination , Matrix4x4 matrix )
232232 where TPixel : unmanaged, IPixel < TPixel >
233- => this . ColorTable = null ;
233+ {
234+ this . ColorTable = null ;
235+
236+ // If the color type is RGB and we have a transparent color, we need to switch to RGBA
237+ // so that we do not incorrectly preserve the obsolete tRNS chunk.
238+ if ( this . ColorType == PngColorType . Rgb && this . TransparentColor . HasValue )
239+ {
240+ this . ColorType = PngColorType . RgbWithAlpha ;
241+ this . TransparentColor = null ;
242+ }
243+
244+ // The same applies for Grayscale.
245+ if ( this . ColorType == PngColorType . Grayscale && this . TransparentColor . HasValue )
246+ {
247+ this . ColorType = PngColorType . GrayscaleWithAlpha ;
248+ this . TransparentColor = null ;
249+ }
250+ }
234251
235252 /// <inheritdoc/>
236253 IDeepCloneable IDeepCloneable . DeepClone ( ) => this . DeepClone ( ) ;
You can’t perform that action at this time.
0 commit comments