分类目录
文章索引模板
wpf显示GIF - 九月 19, 2009 by yippee

wpf显示GIF


第三方控件
用浏览器控件
HOST WINFORM的PICTUREBOX
用MEDIAELEMENT
读取GIF文件自己解码显示
调用解码类一个图片一个图片解析出来定时器
//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());
    }



.Victor’s BLOG: GIF文件格式详解
http://blog.zhongmoo.cn/2009/05/gif.html



WPF中不支持gif的问题 — Windows Live
http://kimiya25.spaces.live.com/Blog/cns!27A083D4FD9435E9!1308.entry



Disabled Images in WPF – Andrew Smith – Infragistics Community
http://blogs.infragistics.com/blogs/andrew_smith/archive/2008/03/30/disabled-images-in-wpf.aspx



GifBitmapDecoder 类 (System.Windows.Media.Imaging)
http://msdn.microsoft.com/zh-cn/library/system.windows.media.imaging.gifbitmapdecoder.aspx
Stream imageStreamSource = new FileStream(“tulipfarm.gif”, FileMode.Open, FileAccess.Read, FileShare.Read); GifBitmapDecoder decoder = new GifBitmapDecoder(imageStreamSource, BitmapCreateOptions.PreservePixelFormat, BitmapCacheOption.Default);


ImageAnimator.Animate 方法 (System.Drawing)
http://msdn.microsoft.com/zh-tw/library/system.drawing.imageanimator.animate(VS.80).aspx



怎样让我的动画真真的动起来?
http://social.msdn.microsoft.com/forums/zh-TW/232/thread/5ac14de8-c2e1-4076-932a-e9de4b0cebf5/



My animated .gif control for WPF – Pragmatic TSQL Programmer
http://www.solidrockstable.com/blogs/PragmaticTSQL/Lists/Posts/Post.aspx?ID=37



How do I get an animated gif to work in WPF? – Stack Overflow
http://stackoverflow.com/questions/210922/how-do-i-get-an-animated-gif-to-work-in-wpf



Creating Animated GIF files in WPF
http://social.msdn.microsoft.com/Forums/en-US/wpf/thread/6ef358a7-d1ac-4267-91d9-166024aad8ca



CodeProject: Another approach to animated GIF in WPF, with transparency. Free source code and programming help
http://www.codeproject.com/KB/WPF/animatedgifinwpf.aspx



CodeProject: GIF animation in WPF. Free source code and programming help
http://www.codeproject.com/KB/WPF/wpfgifanimator.aspx



[WPF疑难]在WPF中显示动态GIF – this.Study(DateTime.Now) – 博客园
http://www.cnblogs.com/zhouyinhui/archive/2007/12/23/1011555.html



WPF support gif — Windows Live
http://kimiya25.spaces.live.com/Blog/cns!27A083D4FD9435E9!1311.entry



[WPF疑难]在WPF中显示动态GIF_软件_科技时代_新浪网
http://tech.sina.com.cn/s/s/2008-05-20/0751665803.shtml



当WPF遇到了gif_福娃居
http://hi.baidu.com/mych/blog/item/1eb14f545f12a752564e00be.html



How do I get an animated gif to work in WPF? – Stack Overflow
http://stackoverflow.com/questions/210922/how-do-i-get-an-animated-gif-to-work-in-wpf



用C#的winform显示gif动画 – 软件使用 – 欢迎来到海青论坛 – Powered by Discuz!
http://youth.dlmu.edu.cn/bbs/viewthread.php?tid=29151



 

标签:,
0923 MFC JPG GIF 图像显示 比较 - 三月 4, 2007 by yippee

0923 0922 MFC JPG GIF 图像显示 比较

有两种方法:
 0921 MFC JPG GIF 图像显示 OleLoadPicture (2007-3-3)
http://www.yippeesoft.com/blog/p/0921MFCJPGGIFOleLoadPicture.php
· 0922 MFC JPG GIF 图像显示 GDIPLUS (2007-3-2)
http://www.yippeesoft.com/blog/p/0922MFCJPGGIFGDIPLUS.php

分别有如下问题:
OLELOAD:
看上去比较麻烦,并且有个资源释放的问题:
如果是刷新界面比较快,例如定时器为500毫秒,此时资源内存占用不断上升,实在没有办法使用
例如 画完背景 再计时器显示当前时间
如果是1秒,则可以,
当时如果快速最大最小化,也会有同样问题

GDIPLUS:
需要包含GDIPLUS的头文件和LIB,不清楚WIN98兼容如何
一般情况下,可以使用GDI,是个C语言接口,包含windows.h,链接gdi32.lib。
如果你针对的操作系统是XP或以上,那么可以使用GDI+,是个C++语言接口,包含gdiplus.h,链接gdiplus.lib。如果想用C语言,那么包含gdiplusflat.h,链接gdiplus.lib。如果想在早期的操作系统上用,那么需要gdiplus.dll。
如果你做.NET开发,那么需要使用.NET的System::Draw库。
再来你还可以用DirectX或者OpenGL作图。OpenGL是C语言接口,头文件放在Platform SDK的include目录下的gl子目录中,与windows平台相关的部分在windows.h中,其余的可以从www.opengl.org下载,链接opengl32.lib。DirectX的话,去微软下载最新的DirectX SDK和.NET Framework。

还有一个编译问题:按照上述做法:出现:
GdiplusFlat.h(267) : error C2955: \’iterator\’ : use of class template requires template argument list
        O:\\VS6\\VC98\\INCLUDE\\utility(71) : see declaration of \’iterator\’
[hide]只好作为局部变量写入CPP文件中 头文件中不包含 GDIPLUS.H[/hide]

SYMPTOMS
When you build a debug version of a Microsoft Foundation Classes (MFC) application that uses GDI+, you may receive an error message that resembles the following:
error C2660: \’Gdiplus::GdiplusBase::operator new\’ : function does not take 3 parameters

CAUSE
In debug builds, MFC defines a preprocessor macro that expands the new operator to an overloaded new operator that takes two extra parameters. The extra parameters are the source file name and code line number. MFC can use this information to report memory leaks to the programmer when in debug mode. This works for MFC classes because MFC provides overloads for new that accept the extra parameters.
However, because this expansion is done by the preprocessor, it affects all usage of the new operator. If any non-MFC classes are used in the project, their new operator is also expanded, even if no suitable overload of new is available in that class. This is what happens in GDI+, and as a result, you receive a compile-time error message.

WORKAROUND
To work around this problem, choose one of the following methods: • Turn off the preprocessor expansion by commenting out the following lines of code in the source file: #ifdef _DEBUG
#define new DEBUG_NEW
#endif

 

Rendering GIF, JPEG, Icon, or Bitmap Files with OleLoadPicture

\’Code by Shige
Private Type TGUID
    Data1 As Long
    Data2 As Integer
    Data3 As Integer
    Data4(0 To 7) As Byte
End Type
Private Declare Function OleLoadPicturePath Lib "oleaut32.dll" (ByVal szURLorPath As Long, ByVal punkCaller As Long, ByVal dwReserved As Long, ByVal clrReserved As OLE_COLOR, ByRef riid As TGUID, ByRef ppvRet As IPicture) As Long
Public Function LoadPicture(ByVal strFileName As String) As Picture
Dim IID  As TGUID
    With IID
        .Data1 = &H7BF80980
        .Data2 = &HBF32
        .Data3 = &H101A
        .Data4(0) = &H8B
        .Data4(1) = &HBB
        .Data4(2) = &H0
        .Data4(3) = &HAA
        .Data4(4) = &H0
        .Data4(5) = &H30
        .Data4(6) = &HC
        .Data4(7) = &HAB
    End With
On Error GoTo ERR_LINE
    OleLoadPicturePath StrPtr(strFileName), 0&, 0&, 0&, IID, LoadPicture
    Exit Function
ERR_LINE:
    Set LoadPicture = VB.LoadPicture(strFileName)
End Function
Private Sub Form_Load()
    Set Me.Picture = LoadPicture("http://www.allapi.net/images/allapi_logo.gif")
End Sub

标签:, , , ,

0921 MFC JPG GIF 图像显示 OleLoadPicture - 三月 3, 2007 by yippee

0921 MFC JPG GIF 图像显示 OleLoadPicture

资料:
在MFC程序中显示JPG/GIF图像
TRACE("dc.SetBkMode( TRANSPARENT );\\r\\n");
CPaintDC dc(this); // device context for painting

dc.SetBkMode( TRANSPARENT );
CFile mFile;
LONG  nLength;

//1 打开文件并获得文件的真实大小
if ( mFile.Open( _T( "c:/1.jpg" ),CFile::modeRead )
 &&( ( nLength = mFile.GetLength() ) > 0 ) )
&leftsign;
 //2 从堆中分配指定数量字节的一整块,这时系统无法提供零零碎碎的局部或全局的堆
 HGLOBAL hGlobal = GlobalAlloc(GMEM_MOVEABLE, nLength );
 LPVOID pvData = NULL;
 if ( hGlobal != NULL )
 &leftsign;
  //3 锁定全局内存对象并返回它的首地址
  if ( ( pvData = GlobalLock(hGlobal) ) != NULL )
  &leftsign;
   //4 把文件内容读进全局内存对象的地址空间中
   mFile.Read( pvData, nLength );
   mFile.Close();
   
   //5 GlobalUnlock函数把以GMEM_MOVEABLE方式分配的内存对象的锁定计数器减1
   GlobalUnlock( hGlobal );
   
   //6 从全局内存中创建stream对象,第二个参数指定当stream释放时是否自动释放全局内存
   IStream *pStm;
   CreateStreamOnHGlobal( hGlobal, TRUE, &pStm) ;
   
   //7 创建一个新的picture对象并用stream对象中的内容初始化
   IPicture *pPic;
   if( SUCCEEDED( OleLoadPicture( pStm, nLength, FALSE, IID_IPicture, (LPVOID*)&pPic ) ) )
   &leftsign;
    //8 释放不要的stream对象并清空stream指针
    pStm->Release();
    pStm=NULL;
    
    OLE_XSIZE_HIMETRIC mWidth;
    OLE_YSIZE_HIMETRIC mHeight;
    
    //9 得到picture对象中图片的宽和高
    pPic->get_Width( &mWidth );
    pPic->get_Height( &mHeight );
    
    CRect rc;
    GetClientRect( &rc );
    double fX,fY;
    
    //10 GetDeviceCaps(HORZRES)得到屏幕的宽度(单位:像素)
    //    GetDeviceCaps(HORZSIZE)得到屏幕的宽度(单位:毫米)
    fX = (double) dc.GetDeviceCaps(HORZRES) * (double)mWidth / ( (double)dc.GetDeviceCaps( HORZSIZE ) * 100.0 );
    fY = (double) dc.GetDeviceCaps(VERTRES) * (double)mHeight / ( (double)dc.GetDeviceCaps( VERTSIZE ) *100.0 );
    
    
    
    //11 把图像显示在dc中
    
    if( FAILED( pPic->Render( dc.GetSafeHdc(), 0, 0, (DWORD)fX , (DWORD)fY , 0, mHeight, mWidth, -mHeight, NULL ) ) )
     AfxMessageBox( _T("渲染图片失败") );
    
    
    CRect rcClient;
    GetClientRect( &rcClient );
    
    BOOL bWidth = rcClient.Width() / fX > rcClient.Height() / fY;
    if ( bWidth )
    &leftsign;
     if( FAILED( pPic->Render( dc.GetSafeHdc(), 0, 0, (DWORD)rcClient.Width() , (DWORD)rcClient.Width() * fY / fX , 0, mHeight, mWidth, -mHeight, NULL ) ) )
      AfxMessageBox( _T("渲染图片失败") );
    &rightsign;
    else
    &leftsign;
     if( FAILED( pPic->Render( dc.GetSafeHdc(), 0, 0, (DWORD)rcClient.Height() * fX/ fY, (DWORD)rcClient.Height() , 0, mHeight, mWidth, -mHeight, NULL ) ) )
      AfxMessageBox( _T("渲染图片失败") );
    &rightsign;
    
    
    //12 释放不要的picture对象,并把指针清空
    pPic->Release();
    pPic=NULL;
    //      delete pStm;
    //13 释放不要的全局内存对象,这个千万别忘了(32位程序不需要这行,系统会自动释放;16位程序一定要)
    FreeResource(hGlobal);
    
   &rightsign;
   else
    AfxMessageBox( _T("从stream中装载图片失败") );
   
  &rightsign;
 &rightsign;
 else
  AfxMessageBox( _T("分配内存失败") );
&rightsign;
else
 AfxMessageBox( _T("打开文件失败") );

标签:, , ,
0922 MFC JPG GIF 图像显示 GDIPLUS - 三月 2, 2007 by yippee

0922 MFC JPG GIF 图像显示 GDIPLUS

资料:
用GDI+(VC)
添加Gdiplus.lib到工程中
头文件中添加
#include "Gdiplus.h"
using namespace Gdiplus;

添加类成员变量
GdiplusStartupInput m_gdiPlusInPut;
ULONG_PTR m_gdiPlusToken;
构造函数中初始化GDI+
 GdiplusStartup( &m_gdiPlusToken, &m_gdiPlusInPut, NULL );

析构函数中 //销毁GDI+
GdiplusShutdown(gdiplusToken);

OnPaint()中
 //CDialog::OnPaint();
  CPaintDC dc( this );
 //建立图形对象
  Graphics mGraphics( dc.GetSafeHdc() );
  //装入图像文件
  Image img( L"./res/test.jpg", TRUE );
 //在指定区域pdestPoints显示图像
  /*//根据背景大小按比例缩放
  CRect rcClient;
  GetClientRect( &rcClient );
 
  BOOL bWidth = rcClient.Width() / img.GetWidth() > rcClient.Height() / img.GetHeight();
  if ( bWidth )
  &leftsign;
   mGraphics.DrawImage( &img, 0, 0, rcClient.Width(), rcClient.Width() * img.GetHeight() / img.GetWidth() );
  &rightsign;
  else
  &leftsign;
   mGraphics.DrawImage(&img, 0, 0, rcClient.Height() * img.GetWidth() / img.GetHeight(), rcClient.Height() );
  &rightsign;
  */

//原始大小
  mGraphics.DrawImage(&img, 0, 0, img.GetWidth(), img.GetHeight() );

问题:
http://www .codeguru.com/ code/legacy/gdi/GDIPlus.zip
包含了头文件和库(.dll和.lib形式的都有)
我在编译过程中出现了编译错误:ULONG_PTR没被定义。错误在GdiPlusInit.h中
typedef Status (WINAPI *NotificationHookProc)(OUT ULONG_PTR *token);
一行。
然后我在GdiPlusInit.h中
typedef Status (WINAPI *NotificationHookProc)(OUT ULONG_PTR *token);
语句前加了
typedef? unsigned long* ULONG_PTR;
一行,编译通过。

在VC中使用GDI+步骤
1把include和Lib文件夹放到程序文件夹,设置里边把.lib文件包含进去,选项里边把include和Lib文件夹
包含进去,

2 把#ifndef ULONG_PTR
  #define ULONG_PTR unsigned long*
  #include "GdiPlus.h"
  using namespace Gdiplus;
  #endif
包含到文件中。

3 在OnInitDialog() 开始GdiplusStartup(&m_gdiplusToken, &m_gdiplusStartupInput, NULL);

4  在OnDestroy()中结束GDI+, GdiplusShutdown(m_gdiplusToken);

5 在OnPaint()或OnDraw()中操作GDI+中的函数和方法。Graphic类等。如Graphic *g; g->DrawLine();

g->DrawImage();等。

标签:, , ,