C
C#2w ago
BlckViper

png image but background is not transparent

Can somebody help me out? The original image is attached
No description
No description
16 Replies
BlckViper
BlckViper2w ago
I have a problem. I have a png but the background is not transparent as presented in the attached img. If you have an answer please ping me ^^ :pepeOkayThumb:
Keswiik
Keswiik2w ago
What exactly are you trying to do? Just posting two pictures and saying "background is not transparent" doesn't give anyone useful info.
BlckViper
BlckViper2w ago
public void ShowImage(string imagePath)
{
Bitmap image = new Bitmap(imagePath);


image.MakeTransparent(Color.Transparent);

PictureBox pictureBox = new PictureBox
{
Image = image,
SizeMode = PictureBoxSizeMode.AutoSize,

};
this.Controls.Add(pictureBox);
this.ClientSize = pictureBox.Size;
}
public void ShowImage(string imagePath)
{
Bitmap image = new Bitmap(imagePath);


image.MakeTransparent(Color.Transparent);

PictureBox pictureBox = new PictureBox
{
Image = image,
SizeMode = PictureBoxSizeMode.AutoSize,

};
this.Controls.Add(pictureBox);
this.ClientSize = pictureBox.Size;
}
If that helps kind a bit
Keswiik
Keswiik2w ago
Is this WPF? WinForms?
BlckViper
BlckViper2w ago
c# win forms with .net
Keswiik
Keswiik2w ago
What is the background color of your picturebox?
Buddy
Buddy2w ago
Winforms doesn't exactly support transparency, not very well at least.
BlckViper
BlckViper2w ago
Should be transparent. Yeah i think thats the problem i‘m running into :hidethepain:
BlckViper
BlckViper2w ago
Hm, I‘ll try it later after I‘m home from work :harold: But it isn't a button. Can you show me with a little snippet what you mean? 😄
Buddy
Buddy2w ago
Button has nothing to do with it all controls have a BackColor property
BlckViper
BlckViper2w ago
Okay Can you give me a little snippet of what you mean? Like insert it into the snippet if its that what you mean?
Buddy
Buddy2w ago
No. Read the docs
BlckViper
BlckViper7d ago
Thanks a lot for your comment but the parameter with .BackColor = Color.Transparent doesn't work
Motley
Motley7d ago
Pretty sure you don't actually want image.MakeTransparent(Color.Transparent); you use that to make a color that is NOT already transparent into a transparent color. For example changing solid pure white to transparent. It has been a long time since I've dealt with this, so take that with a grain of salt. Also, why add a picturebox to the control isntead of just setting the background of the control? If you really need the picturebox, then make the picturebox background transparent too at the very least.
BlckViper
BlckViper5d ago
@Motley I think I already tried that but it doesn’t work