1

I want to show a transparent animated gif picture above another picture in a WinForm.
But the problem is animated gif image is not transparent & has a white background.
How can i make that animated gif transparent?


Here is my animated gif (It has a transparent background):

animated gif

And here is my orange picture :

orange picture

And here is my winform after load :

Transparent animated gif picture above another picture

As you see Loading... image has white background.
How can i transparent it?


**THIS IS NOT DUPLICATE, THE ANSWER [HERE][4] DID N'T SOLVE MY PROBLEM.** **PLEASE TEST MY ANIMATED GIF & YOU WILL SEE WHAT AM I SAYING!**
Vizel Leonid
  • 456
  • 7
  • 15
SilverLight
  • 19,668
  • 65
  • 192
  • 300
  • Your gif just worked fine for me. Is your picturebox is in another control? And as you mentioned `pictureBox.BackColor = Color.Transparent;` didn't work for you? – Muhammad Hannan May 02 '19 at 20:53
  • Gif doesn't really support transparency. – TaW May 02 '19 at 20:55
  • @TaW So what should i do? – SilverLight May 02 '19 at 20:55
  • Not sure. - You could change the gif to an orange background (in a gif editor) or draw the animation yourself or forget about the glitz.. Or maybe one could set your orange to be the transparency color of the gif; but I don't know if that is supported in animated gifs – TaW May 02 '19 at 21:02
  • @Muhammad Hannan I have a panel. I've added "PictureBox1 = Orange Image" to that panel. (Dock = Filled). Then I've added "PictureBox2 = Loading..." above PictureBox1. > Please see my edit > I've added orange picture. – SilverLight May 02 '19 at 21:08
  • @Muhammad Hannan didn't work for you? didn't work – SilverLight May 02 '19 at 21:10
  • You can use the [ImageAnimator](https://learn.microsoft.com/en-us/dotnet/api/system.drawing.imageanimator) class to animate that Bitmap (it allows to specify a Point to define the the Image position). Note that this image is not intended to be shown on a background much different than White. You'll have a very bad *effect* on darker colors. Anyway, if you set all your controls to the same BackColor, it will work anyway (so you'll see what happens :). – Jimi May 02 '19 at 21:15
  • Found the cause of issue. Actually your gif background is actually transparent but your form background is set to `white or control`. You can set the form color to match your orange background then your issue will resolve. – Muhammad Hannan May 02 '19 at 21:16
  • It is a duplicate. – LarsTech May 02 '19 at 21:30
  • @LarsTech I told you. This is not duplicate. This is about animated gif. Not png images. Read my situation carefully man. – SilverLight May 02 '19 at 21:39
  • I did. I downloaded your gif, too. I get an orange background. Try those answers from the linked post and see what is different about your situation. Otherwise, post code that duplicates the problem. – LarsTech May 02 '19 at 21:40
  • @LarsTech Do not use orange background. Use my Orange Picture for PictureBox1 & Loading... gif for PictureBox2. Two pictureboxes! Not one in orange background. – SilverLight May 02 '19 at 21:48
  • WinForm Controls will only be transaparent to the parent container. Like the answer posted below and from the links, you would have to make the gif PictureBox a child of the jaxx liberty PictureBox. – LarsTech May 02 '19 at 21:54
  • you would have to make the gif PictureBox a child of the jaxx liberty PictureBox! How can i do that? – SilverLight May 02 '19 at 21:59
  • Look at the first line of code from the answer you downvoted. – LarsTech May 02 '19 at 22:00
  • It seems it works, but how can i fix this problem in design time? – SilverLight May 02 '19 at 22:07
  • Have you tried to simply use the same BackColor for all your PictureBoxes? Or set the animation as the `PictureBox.Image` property, using a single PictureBox? – Jimi May 02 '19 at 22:23
  • PictureBox controls were designed *not* to be container controls, which is why the designer won't do your bidding. – LarsTech May 02 '19 at 22:23
  • https://stackoverflow.com/a/37473192/3110834 – Reza Aghaei May 03 '19 at 15:44

1 Answers1

6

Actually the answer from here works You have to set the gif-picturebox above the other one (as child) and set it's BackColor to Transparent

imgBackImage.Controls.Add(imgGifImage);
imgGifImage.BackColor = Color.Transparent;

The first line of these codes is the key.

image

SilverLight
  • 19,668
  • 65
  • 192
  • 300