Transparency + Colors lost after Resize of a Transparent Image #2222
-
PngEncoder encoder = new PngEncoder();
encoder.ColorType = PngColorType.RgbWithAlpha;
encoder.TransparentColorMode = PngTransparentColorMode.Preserve;
encoder.BitDepth = PngBitDepth.Bit8;
encoder.CompressionLevel = PngCompressionLevel.BestSpeed;
using (Image<SixLabors.ImageSharp.PixelFormats.Rgba32> image = Image.Load<SixLabors.ImageSharp.PixelFormats.Rgba32>(stream))
{
ResizeOptions resizeOptions = new ResizeOptions
{
Mode = ResizeMode.Max,
PremultiplyAlpha = true
};
image.Mutate(x => x.Resize(Math.Min(image.Width, 1024), Math.Min(image.Height, 1024)));
image.SaveAsPngAsync(Exporter.Folder + "\\" + textureNames[3] + ".png", encoder);
} Like the Titel says, when I run this on an Image with Alpha = 0, the resized image becomes a totally blank one where all values RGBA are zero. |
Beta Was this translation helpful? Give feedback.
Answered by
JimBobSquarePants
Sep 1, 2022
Replies: 1 comment 8 replies
-
I don't fully understand what you are saying here. Are you saying that if you resize an image where the alpha component of the image is 0, then the result has 0 for red, green, blue components? If so, that makes perfect sense since you are pre-multiplying the other components by the alpha value. You should set |
Beta Was this translation helpful? Give feedback.
8 replies
Answer selected by
JimBobSquarePants
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
I don't fully understand what you are saying here. Are you saying that if you resize an image where the alpha component of the image is 0, then the result has 0 for red, green, blue components?
If so, that makes perfect sense since you are pre-multiplying the other components by the alpha value. You should set
ResizeOptions.PremultiplyAlpha
tofalse
to avoid this.