Skip to content
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

How to set the image rounded transparent background ? #23

Closed
t-jian opened this issue Jan 12, 2024 · 2 comments
Closed

How to set the image rounded transparent background ? #23

t-jian opened this issue Jan 12, 2024 · 2 comments

Comments

@t-jian
Copy link

t-jian commented Jan 12, 2024

I followed the example given by github to generate the circular image.
However, the generated image has a blac background after being exported
How do I set a transparent background?
var logoRequest = (HttpWebRequest)WebRequest.Create("https://vip.ztan.net/upload/image/2023-0209/384134265131077.png"); HttpWebResponse logoResponse = (HttpWebResponse)logoRequest.GetResponse(); using Stream logoResponseStream = logoResponse.GetResponseStream(); var logo = Image.Load(logoResponseStream); logo= logo.Clone(x => x.ConvertToAvatar(new Size(80, 80), 80 / 2)); using var stream = new MemoryStream(); await logo.SaveAsync(stream, new PngEncoder()); stream.Position = 0; return stream.ToArray();
ConvertToAvatar code refer to https://github.com/SixLabors/Samples/blob/main/ImageSharp/AvatarWithRoundedCorner/Program.cs

c2896e5d-ff66-480a-b6e2-d45fec0f8187

@JimBobSquarePants
Copy link
Member

Make sure you are using a pixel format that supports an alpha component and also ensure the encoder uses a color type that supports an alpha component. Your input image will be 24bit so you need to explicitly override that.

@t-jian
Copy link
Author

t-jian commented Jan 12, 2024

Thank you. I've made it

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants