• <ins id="pjuwb"></ins>
    <blockquote id="pjuwb"><pre id="pjuwb"></pre></blockquote>
    <noscript id="pjuwb"></noscript>
          <sup id="pjuwb"><pre id="pjuwb"></pre></sup>
            <dd id="pjuwb"></dd>
            <abbr id="pjuwb"></abbr>
            隨筆-341  評論-2670  文章-0  trackbacks-0
                自從我發現Windows XP開始就支持Windows Image Component之后,我發現讀取圖片這個問題瞬間就變簡單了。因此我給GacUI添加了繪制圖片的功能,并做了一個小小的GIF動畫demo。代碼仍然更新在了Vczh Library++3.0上的Candidate\GUI\GUIDemo\GUIDemo.sln上。F5可以直接運行,不過如果要雙擊打開exe的話,則要把GUIDemo\Resources目錄復制到exe目錄下。下面的效果圖展示了一個GIF動畫上覆蓋若干個帶有alpha通道的png圖片:

            (實際效果是會動的)

                因為GacUI試圖隔離Windows API的所有信息,以便可以讓程序員自由添加對操作系統(Windows或其他)和渲染技術(GDI、Direct2D或其他)的支持,因此我不得不暫時封裝了一下。現在的這個接口只能讀,不能做一些高級操作,以后會添加上。使用GacUI編寫上述Demo的代碼如下(具體實現可以去下載并閱讀):
              1 #include "..\..\GUI\GacUI.h"
              2 
              3 GuiBoundsComposition* CreateImageFrame(Ptr<INativeImage> image, int frameIndex=0)
              4 {
              5     GuiImageFrameElement* element=GuiImageFrameElement::Create();
              6     element->SetImage(image, frameIndex);
              7 
              8     GuiBoundsComposition* composition=new GuiBoundsComposition;
              9     composition->SetOwnedElement(element);
             10     composition->SetMinSizeLimitation(GuiGraphicsComposition::LimitToElement);
             11     return composition;
             12 }
             13 
             14 class GifAnimation : public Object, public IGuiGraphicsAnimation
             15 {
             16 protected:
             17     unsigned __int64            startTime;
             18     GuiImageFrameElement*        element;
             19 public:
             20     GifAnimation(GuiImageFrameElement* _element)
             21         :element(_element)
             22         ,startTime(DateTime::LocalTime().totalMilliseconds)
             23     {
             24     }
             25 
             26     int GetTotalLength()
             27     {
             28         return 1;
             29     }
             30 
             31     int GetCurrentPosition()
             32     {
             33         return 0;
             34     }
             35 
             36     void Play(int currentPosition, int totalLength)
             37     {
             38         unsigned __int64 ms=DateTime::LocalTime().totalMilliseconds-startTime;
             39         int frameIndex=(ms/100)%element->GetImage()->GetFrameCount();
             40         element->SetImage(element->GetImage(), frameIndex);
             41     }
             42 
             43     void Stop()
             44     {
             45     }
             46 };
             47 
             48 void SetupGifWindow(GuiControlHost* host)
             49 {
             50     host->GetBoundsComposition()->SetMinSizeLimitation(GuiGraphicsComposition::LimitToElementAndChildren);
             51     INativeImageProvider* imageProvider=GetCurrentController()->GetImageProvider();
             52     Ptr<INativeImage> imageNew=imageProvider->CreateImageFromFile(L"Resources\\New.png");
             53     Ptr<INativeImage> imageOpen=imageProvider->CreateImageFromFile(L"Resources\\Open.png");
             54     Ptr<INativeImage> imageSave=imageProvider->CreateImageFromFile(L"Resources\\Save.png");
             55     Ptr<INativeImage> imageGif=imageProvider->CreateImageFromFile(L"Resources\\Gif.gif");
             56 
             57     GuiBoundsComposition* image1=CreateImageFrame(imageNew);
             58     GuiBoundsComposition* image2=CreateImageFrame(imageOpen);
             59     GuiBoundsComposition* image3=CreateImageFrame(imageSave);
             60     GuiBoundsComposition* image4=CreateImageFrame(imageGif);
             61     
             62     host->GetContainerComposition()->AddChild(image4);
             63     host->GetContainerComposition()->AddChild(image1);
             64     host->GetContainerComposition()->AddChild(image2);
             65     host->GetContainerComposition()->AddChild(image3);
             66 
             67     image1->SetBounds(Rect(Point(1010), imageNew->GetFrame(0)->GetSize()));
             68     image2->SetBounds(Rect(Point(5010), imageOpen->GetFrame(0)->GetSize()));
             69     image3->SetBounds(Rect(Point(9010), imageSave->GetFrame(0)->GetSize()));
             70 
             71     Ptr<GifAnimation> animation=new GifAnimation(image4->GetOwnedElement().Cast<GuiImageFrameElement>().Obj());
             72     host->GetGraphicsHost()->GetAnimationManager()->AddAnimation(animation);
             73 }
             74 
             75 /***********************************************************************
             76 GuiMain
             77 ***********************************************************************/
             78 
             79 void GuiMain()
             80 {
             81     INativeWindow* window=GetCurrentController()->CreateNativeWindow();
             82 #ifdef GUI_GRAPHICS_RENDERER_GDI
             83     window->SetTitle(L"Vczh GUI Demo (GDI)");
             84 #endif
             85 #ifdef GUI_GRAPHICS_RENDERER_DIRECT2D
             86     window->SetTitle(L"Vczh GUI Demo (Direct2D)");
             87 #endif
             88     window->SetClientSize(Size(800600));
             89 
             90     INativeScreen* screen=GetCurrentController()->GetScreen(window);
             91     Rect windowBounds=window->GetBounds();
             92     Rect screenBounds=screen->GetClientBounds();
             93     window->SetBounds(Rect(
             94         Point(
             95             screenBounds.Left()+(screenBounds.Width()-windowBounds.Width())/2,
             96             screenBounds.Top()+(screenBounds.Height()-windowBounds.Height())/2
             97             ),
             98         windowBounds.GetSize()
             99         ));
            100 
            101     GuiControlHost host(new win7::Win7WindowStyle);
            102     SetupGifWindow(&host);
            103     host.SetNativeWindow(window);
            104 
            105     GetCurrentController()->Run(window);
            106 }


            posted on 2011-11-06 01:00 陳梓瀚(vczh) 閱讀(2235) 評論(5)  編輯 收藏 引用 所屬分類: GacUI

            評論:
            # re: GacUI支持包括GIF和PNG在內的多種圖片格式 2011-11-06 18:28 | phoenixbing
            一個女人,拿著鞭子,太邪惡了.  回復  更多評論
              
            # re: GacUI支持包括GIF和PNG在內的多種圖片格式 2011-11-06 21:21 | ISA-信息科學社
            命名方式值得大家學習。  回復  更多評論
              
            # re: GacUI支持包括GIF和PNG在內的多種圖片格式 2011-11-06 21:26 | 陳梓瀚(vczh)
            @phoenixbing
            寒蟬鳴泣之時,神片啊  回復  更多評論
              
            # re: GacUI支持包括GIF和PNG在內的多種圖片格式 2011-11-07 20:23 | iloveprogramme
            @陳梓瀚(vczh)
            要確實是神片的話去看看。
            現在除了在追幾部有限的漫畫外,挺長時間不看動畫了。
              回復  更多評論
              
            # re: GacUI支持包括GIF和PNG在內的多種圖片格式 2011-11-07 20:53 | 陳梓瀚(vczh)
            @iloveprogramme
            兩部都要看完,否則會不知所云的。  回復  更多評論
              
            国内精品伊人久久久久影院对白| 欧美伊人久久大香线蕉综合69| 一级a性色生活片久久无 | 久久SE精品一区二区| 97精品依人久久久大香线蕉97| 久久男人Av资源网站无码软件| 99精品久久精品| 一级A毛片免费观看久久精品| 一级女性全黄久久生活片免费| 无码专区久久综合久中文字幕| 亚洲国产成人精品女人久久久| 亚洲精品国产字幕久久不卡| 狠狠色综合久久久久尤物 | 国产精品美女久久久久| 伊人久久大香线蕉无码麻豆| 久久精品www人人爽人人| 国内精品久久久久久不卡影院| 久久精品中文无码资源站| 日韩欧美亚洲综合久久影院d3| 久久久久久久97| 久久午夜福利电影| 亚洲精品国产综合久久一线| 成人免费网站久久久| 亚洲国产精品无码久久一线| 久久久久18| 久久久久久综合网天天| 久久不见久久见免费影院www日本| 久久99久久99精品免视看动漫| 久久国产精品免费一区| 久久免费精品一区二区| 国产一级做a爰片久久毛片| 丁香五月网久久综合| 中文字幕无码免费久久| 久久99热这里只有精品国产| 最新久久免费视频| 中文字幕无码久久精品青草| 三级片免费观看久久| 性做久久久久久久久老女人| 久久人人爽人人爽AV片| 久久亚洲国产成人精品无码区| 久久国产成人精品国产成人亚洲|