DaniWeb IT Discussion Community

DaniWeb IT Discussion Community (http://www.daniweb.com/forums/index.php)
-   C# (http://www.daniweb.com/forums/forum61.html)
-   -   Gif image Extraction (http://www.daniweb.com/forums/thread138789.html)

pradeepachari Aug 6th, 2008 5:44 am
Gif image Extraction
 
Below is my code . Actually i want to know in which frame number image resides
and also i want to know number of frames in b/n each image

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;



namespace WindowsApplication1
{
public partial class Form1 : Form
{
public Bitmap bmp;
public Image Img;
public System.Collections.ArrayList colFrame;
private int _FrameCount;
public Form1()
{
InitializeComponent();
}

private void Form1_Load(object sender, EventArgs e)
{

Img = Image.FromFile("c:\\triple\\diniout.gif");

colFrame = new System.Collections.ArrayList();
System.Drawing.Imaging.FrameDimension fdl = new System.Drawing.Imaging.FrameDimension(Img.FrameDimensionsList[0]);

_FrameCount = Img.GetFrameCount(fdl) ;

// ExtractImageFrames();
if(ImageAnimator.CanAnimate(Img))
{
ImageAnimator.Animate(Img, new EventHandler(this.onFrameChanged));
}

}
private void onFrameChanged(object sender, EventArgs e)
{
// MessageBox.Show(bAnimationEnd.ToString());


if (bAnimationEnd<0)
{
ImageAnimator.StopAnimate(Img, this.onFrameChanged);
Img.Dispose();
return;
}


// ExtractImageFrames();
// ImageAnimator.UpdateFrames(Img);
this.Invalidate();


}
protected override void OnPaint(PaintEventArgs e)
{

////Bitmap tmpBmp = new Bitmap(Img.Width, Img.Height);
////Graphics g = Graphics.FromImage(tmpBmp);

//ExtractImageFrames();
e.Graphics.DrawImage(this.Img, new Point(0, 0));
////g.DrawImage(Img, 0, 0);
////g.Save();
e.Graphics.Save();
ExtractImageFrames();
////string tmpName = "img";
////tmpName = tmpName + _FrameCount.ToString() + ".bmp";

////tmpBmp.Save("c:\\" + tmpName);
////colFrame.Add(tmpBmp);
ImageAnimator.UpdateFrames(Img);


}
public void ExtractImageFrames()
{
Bitmap tmpBmp = new Bitmap(Img.Width, Img.Height);
Graphics g = Graphics.FromImage(tmpBmp);
//Graphics g = System.Drawing.Image.FromFile("c:\\image011.gif");
g.DrawImage(Img, 0, 0);
g.Save();
string tmpName = "imgArtdiniout";
tmpName = tmpName + _FrameCount.ToString() + ".bmp";
tmpBmp.Save("c:\\triple\\" + tmpName);
colFrame.Add(tmpBmp);




}
public int FrameCount
{

get
{
_FrameCount = _FrameCount - 1;
return _FrameCount;

}
}
public int bAnimationEnd
{
get{
return FrameCount;


}
}


}
}


All times are GMT -4. The time now is 6:56 am.

Forum system based on vBulletin Copyright ©2000 - 2009, Jelsoft Enterprises Ltd.
©2003 - 2009 DaniWeb® LLC