avinash_takale
asked on
how to make background transparent for animated gif
hi experts,
I want to set background as transparent for gif.
is there any to set to transparent in C#
thanks in advance.
I want to set background as transparent for gif.
is there any to set to transparent in C#
thanks in advance.
ASKER
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
but i can't get good answer from this.
so if any one knows this please send this answer.
its really urgent
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);
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);
ASKER
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
but if we assign gif to bmp then it will not animate
so is there any solution
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.gi f");
bool currentlyAnimating = false;
//This method begins the animation.
public void AnimateImage()
{
if (!currentlyAnimating)
{
//Begin the animation only once.
ImageAnimator.Animate(anim atedImage, new EventHandler(this.OnFrameC hanged));
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. animatedIm age, new Point(0, 0));
}
public static void Main()
{
Application.Run(new animateImage());
}
}
using System;
using System.Drawing;
using System.Windows.Forms;
public class animateImage : Form
{
//Create a Bitmpap Object.
Bitmap animatedImage = new Bitmap("SampleAnimation.gi
bool currentlyAnimating = false;
//This method begins the animation.
public void AnimateImage()
{
if (!currentlyAnimating)
{
//Begin the animation only once.
ImageAnimator.Animate(anim
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.
}
public static void Main()
{
Application.Run(new animateImage());
}
}
private void FormSplash_Load(object sender, EventArgs e)
{
Stream imgStream = null;
Assembly a = Assembly.GetExecutingAssem bly();
// attach to stream to the resource in the manifest
imgStream = a.GetManifestResourceStrea m "BWC.Entertainment.BasicSp lash.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(bit map.GetPix el(0,0));
this.BackgroundImage = bitmap;
this.TransparencyKey = bitmap.GetPixel(0,0);
imgStream.Close();
imgStream = null;
}
this.Visible = false;
Version ver = System.Reflection.Assembly .GetEntryA ssembly(). GetName(). Version;
string version = ver.Major + "." + ver.Minor + "." + ver.Build + "." + ver.Revision;
SetMillOrderAppVersion( version );
this.lblVersionInfo.BringT oFront();
this.lblStatus.BringToFron t();
this.tbAppTitle.BringToFro nt();
this.lblStatus.Refresh();
this.tbAppTitle.Refresh();
this.lblVersionInfo.Refres h();
// this.Invalidate();
}
{
Stream imgStream = null;
Assembly a = Assembly.GetExecutingAssem
// attach to stream to the resource in the manifest
imgStream = a.GetManifestResourceStrea
if( !(null==imgStream) )
{
// create a new bitmap from this stream and
// add it to the arraylist
bitmap = Bitmap.FromStream( imgStream ) as Bitmap;
bitmap.MakeTransparent(bit
this.BackgroundImage = bitmap;
this.TransparencyKey = bitmap.GetPixel(0,0);
imgStream.Close();
imgStream = null;
}
this.Visible = false;
Version ver = System.Reflection.Assembly
string version = ver.Major + "." + ver.Minor + "." + ver.Build + "." + ver.Revision;
SetMillOrderAppVersion( version );
this.lblVersionInfo.BringT
this.lblStatus.BringToFron
this.tbAppTitle.BringToFro
this.lblStatus.Refresh();
this.tbAppTitle.Refresh();
this.lblVersionInfo.Refres
// this.Invalidate();
}
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.
Then we set the bitmap's transparency.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
or have i misunderstood avinash_takale question?
btw, you asume that pixel at 0,0 is for the transparent color? what if that is not for transparent?
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!
yeah, I do.
In creating the images here, I cheat and always make that first pixel represent the color I want to be transparent.
In creating the images here, I cheat and always make that first pixel represent the color I want to be transparent.
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
with both information, the solution is provided.
regards
Ok by me :) I didn't realize he'd posted when I finally sent mine off
this may help:
http://www.c-sharpcorner.com/Code/2003/March/ThumbnailImages.asp
Apresto