显示多帧图像文件

   //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);
   }
 }

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值