Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

how to make background transparent for animated gif

Posted on 2006-07-20
18
Medium Priority
?
1,337 Views
Last Modified: 2012-06-27
hi experts,

I want to set background as transparent for gif.
is there any to set to transparent in C#

thanks in advance.
0
Comment
Question by:avinash_takale
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 6
  • 5
  • 2
  • +1
18 Comments
 
LVL 23

Expert Comment

by:apresto
ID: 17144835
Hi avinash_takale,

this may help:

http://www.c-sharpcorner.com/Code/2003/March/ThumbnailImages.asp

Apresto
0
 
LVL 23

Expert Comment

by:apresto
ID: 17144836
0
 

Author Comment

by:avinash_takale
ID: 17144889
i tried in this way
but i can't get good answer from this.
so if any one knows this please send this answer.
its really  urgent
0
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 
LVL 11

Expert Comment

by:vo1d
ID: 17145271
what do you excactly mean? do you wanna specify the color of your gif, which shall be interpreted as transparent?
do you draw that give by your own?
you will just have to load your give into a bitmap object.
then you have a method like that:
bmp.MakeTransparent(the transparent color);
0
 

Author Comment

by:avinash_takale
ID: 17147006
no i want to make back color as form color for gif.
but if we assign gif to bmp then it will not animate
so is there any solution
0
 
LVL 11

Expert Comment

by:vo1d
ID: 17147741
sure you can. here is an example:

using System;
using System.Drawing;
using System.Windows.Forms;

public class animateImage : Form
{
                     
    //Create a Bitmpap Object.
    Bitmap animatedImage = new Bitmap("SampleAnimation.gif");
    bool currentlyAnimating = false;
                     
    //This method begins the animation.
    public void AnimateImage()
    {
        if (!currentlyAnimating)
        {
                     
            //Begin the animation only once.
            ImageAnimator.Animate(animatedImage, new EventHandler(this.OnFrameChanged));
            currentlyAnimating = true;
        }
    }

    private void OnFrameChanged(object o, EventArgs e)
    {
                     
        //Force a call to the Paint event handler.
        this.Invalidate();
    }

    protected override void OnPaint(PaintEventArgs e)
    {
                     
        //Begin the animation.
        AnimateImage();
                     
        //Get the next frame ready for rendering.
        ImageAnimator.UpdateFrames();
                     
        //Draw the next frame in the animation.
        e.Graphics.DrawImage(this.animatedImage, new Point(0, 0));
    }

    public static void Main()
    {
        Application.Run(new animateImage());
    }
}
0
 
LVL 12

Expert Comment

by:topdog770
ID: 17147979
private void FormSplash_Load(object sender, EventArgs e)
{
Stream imgStream = null;
                  Assembly a = Assembly.GetExecutingAssembly();
                  // attach to stream to the resource in the manifest
                  
imgStream = a.GetManifestResourceStream "BWC.Entertainment.BasicSplash.bmp");
                  if( !(null==imgStream) )
                  {                    
                        // create a new bitmap from this stream and
                        // add it to the arraylist
                        bitmap = Bitmap.FromStream( imgStream ) as Bitmap;
                        bitmap.MakeTransparent(bitmap.GetPixel(0,0));
                        this.BackgroundImage = bitmap;
                        this.TransparencyKey = bitmap.GetPixel(0,0);
                        imgStream.Close();
                        imgStream = null;
                  }      

                  this.Visible = false;
                  Version ver = System.Reflection.Assembly.GetEntryAssembly().GetName().Version;
                  string version = ver.Major + "." + ver.Minor + "." + ver.Build + "." + ver.Revision;
                  SetMillOrderAppVersion( version );

                  this.lblVersionInfo.BringToFront();
                  this.lblStatus.BringToFront();
                  this.tbAppTitle.BringToFront();

                  this.lblStatus.Refresh();
                  this.tbAppTitle.Refresh();
                  this.lblVersionInfo.Refresh();
//                  this.Invalidate();

            }
0
 
LVL 12

Expert Comment

by:topdog770
ID: 17148002
That was more code then needed.. sorry.. the key parts are where we use the first pixel of the bitmap to determine what the transparent color of the bitmap will be..

Then we set the bitmap's transparency.

0
 
LVL 11

Accepted Solution

by:
vo1d earned 2000 total points
ID: 17148783
topdog, why do much code if you just need one line?
bmp.MakeTransparent(the transparent color);
0
 
LVL 11

Expert Comment

by:vo1d
ID: 17148794
or have i misunderstood  avinash_takale question?
0
 
LVL 11

Expert Comment

by:vo1d
ID: 17148802
btw, you asume that pixel at 0,0 is for the transparent color? what if that is not for transparent?
0
 
LVL 12

Expert Comment

by:topdog770
ID: 17148805
nope... I just posted way too much code!  Was doing some other stuff at the time.. thought it was ready to go and hit submit!

0
 
LVL 12

Expert Comment

by:topdog770
ID: 17148813
yeah, I do.

In creating the images here, I cheat and always make that first pixel represent the color I want to be transparent.
0
 
LVL 11

Expert Comment

by:vo1d
ID: 17327549
question has been answered by using the MakeTransparent method of the bitmap object. in addition, a code how to display an animated gif is also provided.
with both information, the solution is provided.
regards
0
 
LVL 12

Expert Comment

by:topdog770
ID: 17376961
Ok by me :)  I didn't realize he'd posted when I finally sent mine off
0

Featured Post

Enroll in October's Free Course of the Month

Do you work with and analyze data? Enroll in October's Course of the Month for 7+ hours of SQL training, allowing you to quickly and efficiently store or retrieve data. It's free for Premium Members, Team Accounts, and Qualified Experts!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction Hi all and welcome to my first article on Experts Exchange. A while ago, someone asked me if i could do some tutorials on object oriented programming. I decided to do them on C#. Now you may ask me, why's that? Well, one of the re…
This article aims to explain the working of CircularLogArchiver. This tool was designed to solve the buildup of log file in cases where systems do not support circular logging or where circular logging is not enabled
How to fix incompatible JVM issue while installing Eclipse While installing Eclipse in windows, got one error like above and unable to proceed with the installation. This video describes how to successfully install Eclipse. How to solve incompa…
Please read the paragraph below before following the instructions in the video — there are important caveats in the paragraph that I did not mention in the video. If your PaperPort 12 or PaperPort 14 is failing to start, or crashing, or hanging, …
Suggested Courses

618 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question