//imageAnimator类能够处理包含时间轴的图像
private:Bitmap^ MyBitmap;
private:bool MyAnimate;
//更新显示设备
public:System::Void OnImageAnimate(System::Object^ sender, System::EventArgs^ e)
{
//System::Threading::Thread::Sleep(100);
this->panel1->Invalidate(this->panel1->ClientRectangle);
}
//浏览图像
private: System::Void button1_Click(System::Object^ sender, System::EventArgs^ e) {
this->MyAnimate = false;
this->openFileDialog1->Filter = "GIF图像文件(*.gif)|*.gif|所有图像文件(JPeg, Gif, Bmp, etc.)|*.jpg;*.jpeg; *.gif;*.bmp;*.tif; *.tiff; *.png| JPeg图像文件(*.jpg;*.jpeg) |*.jpg;*.jpeg |BMP图像文件(*.bmp)|*.bmp|Tiff图像文件(*.tif;*.tiff)| *.tif;*.tiff|Png图像文件(*.png)| *.png |所有文件(*.*)|*.*";
if (this->openFileDialog1->ShowDialog() == System::Windows::Forms::DialogResult::OK)
{
String^ MyFileName = this->openFileDialog1->FileName;
this->textBox1->Text = MyFileName;
this->MyBitmap=(Bitmap^)System::Drawing::Image::FromFile(MyFileName);
if(ImageAnimator::CanAnimate(MyBitmap))//确定此图像是否包基于时间轴的帧
{
this->MyAnimate=true;
//Animate方法用于将多帧图像显式为动画
ImageAnimator::Animate(MyBitmap,gcnew EventHandler(this,&Example::Form1::OnImageAnimate));
}
}
}
//显示动画图像
private: System::Void panel1_Paint(System::Object^ sender, System::Windows::Forms::PaintEventArgs^ e) {
if(this->MyBitmap==nullptr)
return;
if(this->MyAnimate==true)
{
ImageAnimator::UpdateFrames(MyBitmap);//绘制下一帧
e->Graphics->DrawImage(MyBitmap,0, 0);
}
}