Skip to content

Is there a way to control the background color when using rmode=pad #376

Answered by JimBobSquarePants
drgrieve asked this question in Q&A
Discussion options

You must be logged in to vote

Those images are palette-based PNGs which means they have a fixed color set. I would expect whoever provided these images have been pre-optimized for display on the web assuming any alignment would be done via CSS.

ImageSharp by default will preserve any inbound color palette, in your case you are introducing transparency where there is none previously so the encoder will attempt to find a color in the palette which has the closes Euclidian distance to transparent. For example, blue is closer than white to transparent, so you get blue.

What you need to do in this case is to remove the inbound palette from the image metadata via OnBeforeSaveAsync

Something like the following...

ImageSharpM…

Replies: 1 comment 3 replies

Comment options

You must be logged in to vote
3 replies
@drgrieve
Comment options

@JimBobSquarePants
Comment options

Answer selected by drgrieve
@drgrieve
Comment options

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants