-
Notifications
You must be signed in to change notification settings - Fork 49
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Transparent Color on PadTransform #120
Comments
Howdy! Thanks for the detailed write-up. The So, if you start with a source that does not contain transparency, the pipeline's output Here's an example including the format conversion explicitly, which should give your desired result: var settings = ProcessImageSettings.Default;
_ = settings.TrySetEncoderFormat(ImageMimeTypes.Png);
using var outStreamF_PNG = File.Create(StorePathFile_PNG);
using var pipeline = MagicImageProcessor.BuildPipeline(mStream_PNG, settings);
pipeline
.AddTransform(new FormatConversionTransform(PixelFormats.Bgra32bpp))
.AddTransform(new PadTransform(System.Drawing.Color.Transparent, padTop, padRight, padBottom, padLeft))
.WriteOutput(outStreamF_PNG); Note that adding the Also be aware And finally, I agree an additional |
The padding Color.Transparent is inconsistent between the two methods:
Despite the instruction of System.Drawing.Color.Transparent, the padded area is rendered as white.
Whereas setting the ProcessImageSettings with MatteColor = System.Drawing.Color.Transparent will produce a transparent padded area around the image.
I noticed that the documentation for PadTransform says "Adds solid-colored padding pixels to an image." But why would this not honor System.Drawing.Color.Transparent when padding a png image?
When we process images that are larger than the target size, the ProcessImageSettings with CropScaleMod.Pad works perfectly.
But when the source image is smaller than the target size we have to calculate the padding for each side and apply the PadTransform. This is where it fails us. A cropscale mode for padding with the option to not upscale the image would be ideal, but would gladly settle for a solution where the PadTransform option works with Color.Transparent.
The text was updated successfully, but these errors were encountered: