• <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
                自從我發(fā)現Windows XP開始就支持Windows Image Component之后,我發(fā)現讀取圖片這個問題瞬間就變簡單了。因此我給GacUI添加了繪制圖片的功能,并做了一個小小的GIF動畫demo。代碼仍然更新在了Vczh Library++3.0上的Candidate\GUI\GUIDemo\GUIDemo.sln上。F5可以直接運行,不過如果要雙擊打開exe的話,則要把GUIDemo\Resources目錄復制到exe目錄下。下面的效果圖展示了一個GIF動畫上覆蓋若干個帶有alpha通道的png圖片:

            (實際效果是會動的)

                因為GacUI試圖隔離Windows API的所有信息,以便可以讓程序員自由添加對操作系統(tǒng)(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
            兩部都要看完,否則會不知所云的。  回復  更多評論
              
            无码人妻精品一区二区三区久久| 91亚洲国产成人久久精品| 色婷婷狠狠久久综合五月| 久久夜色精品国产亚洲| 91久久婷婷国产综合精品青草 | 久久狠狠高潮亚洲精品| 久久96国产精品久久久| 无码任你躁久久久久久| 国产精品天天影视久久综合网| 久久亚洲电影| 久久亚洲精品视频| 一本色道久久综合狠狠躁| 99久久国产主播综合精品| 亚洲人成伊人成综合网久久久| 91亚洲国产成人久久精品| 人妻精品久久久久中文字幕69| 国产精品美女久久久免费 | 亚洲中文字幕无码久久2017| 色综合久久综精品| 国产成人无码久久久精品一| 偷偷做久久久久网站| 久久强奷乱码老熟女| 久久美女人爽女人爽| 国产成人精品久久免费动漫| 一本色道久久88—综合亚洲精品| 久久久中文字幕日本| 国产福利电影一区二区三区久久久久成人精品综合 | 欧美麻豆久久久久久中文| 久久99中文字幕久久| 精品久久久噜噜噜久久久| 亚洲va久久久噜噜噜久久男同| 一本久久精品一区二区| 久久男人中文字幕资源站| 国产日韩久久久精品影院首页| 嫩草影院久久99| 久久精品国产99国产精品| A级毛片无码久久精品免费| 国产精品无码久久久久| 久久人人爽人爽人人爽av| 亚洲国产婷婷香蕉久久久久久| 亚洲国产小视频精品久久久三级|