• <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>
            隨筆 - 55  文章 - 15  trackbacks - 0
            <2012年9月>
            2627282930311
            2345678
            9101112131415
            16171819202122
            23242526272829
            30123456

            常用鏈接

            留言簿

            隨筆分類

            隨筆檔案

            搜索

            •  

            最新評論

            閱讀排行榜

            評論排行榜

                  不積跬步無以至千里。為什么要說這么一句話呢?是因為我學習Windows 8 開發(fā)是沒有系統(tǒng)性可言的,而且根據微軟MSDN官方的RoadMap進行學習的話我也覺得是零散而且不系統(tǒng)的,所以我的計劃就是自己做個應用,碰到問題解決問題,解決問題記錄問題,記錄問題以便下次遇到可以知道在哪里找到。所以我走的都是一個個雜亂的跬步,但是這是經驗的積累,希望有一天能至千里,我對這一天抱有期望。
                  額,跑題了,今天的主題是添加照片,還是先上圖吧,老規(guī)矩:
                  
            先說說我的解決方案吧,我盡量描述的清楚:
                  這是一個GridView,GridView中放置的是一堆DataItem,每一個DataItem中都有一個Image屬性,也有一個imagePath屬性,用來接收圖片的地址:

                  
             1         public ref class SampleDataCommon : TestViewState::Common::BindableBase
             2         {
             3 
             4         public:
             5               void SetImage(Platform::String^ path);
             6               property Windows::UI::Xaml::Media::ImageSource^ Image { Windows::UI::Xaml::Media::ImageSource^ get(); 
                                                                                                               
            void set(Windows::UI::Xaml::Media::ImageSource^ value); }
             7 
             8         private:
             9 
            10             Windows::UI::Xaml::Media::ImageSource^ _image;
            11             Platform::String^ _imagePath;
            12 
            13         };
            14 


            正如大家所看到的那樣,SetImage(..)方法接收一個String^ 類型的路徑,用來設置圖片。我們來看這個方法做了些什么:
             1 ImageSource^ SampleDataCommon::Image::get()
             2 {
             3     static Uri^ _baseUri = ref new Uri("ms-appx:///");// 待添加 ms-appdata:///    
             4     if (_image == nullptr && _imagePath != nullptr)
             5     {
             6         _image = ref new BitmapImage(_baseUri->CombineUri(_imagePath));// _baseUri + _imagePath
             7         
             8     }
             9     return _image;
            10 }
            11 
            12 void SampleDataCommon::Image::set(ImageSource^ value)
            13 {
            14     if (_image != value)
            15     {
            16         _image = value;
            17         _imagePath = nullptr;
            18         OnPropertyChanged("Image");
            19         PropertySet set;
            20     }
            21 }
            22 
            23 void SampleDataCommon::SetImage(String^ path)
            24 {
            25     _image = nullptr;
            26     _imagePath = path;
            27     OnPropertyChanged("Image");
            28 }
            29 

            SetImage方法只是把path傳遞給back store _imagePath, 通過_imagePath,在Image::get()方法中,我們看到,一個ms-appx:///目錄下的文件被作為源賦給了image。其實這個完整的路徑應該是:ms-appx:///Asset/Gray.png.

            一般文件都有一個路徑,基本上是這樣的:<scheme>://<domain name>/<path>.
            在Windows 8 中,所有的文件都是從App的package中讀取出來的 。代表App的本地打包文件的scheme是“ms-appx:"domain name 可有可無,一般都省略掉,這樣App就假定domain name指的是App package的full name。
            你也可以用 "/"來表示pakage的根目錄,例如:"/pic.png"就是指在你的應用的根目錄下的pic.png。

            Your app doesn't have access to E:\demo folder.  Your application has default access only to items within its app data and app package folders. By declaring the appropriate Capabilities(such as Picture Library access) it can get brokered access to files in libraries.
            If you are loading a hard coded image then it should be in the app package.
            You can't reference images on the file system outside of your package from Xaml, and doing so doesn't make much sense: you can't be sure that those images will even exist. 

                  這幾句話很簡單,就是說,你只能使用包內的路徑,或者你在Capability設置了可以訪問Picture Library的話,你也可以用路徑直接訪問這里面的圖片之類的文件。但是,如果你想使用路徑訪問其他地方的文件,那是不可能的。怎么辦?使用流:

                  我錯了,忘了把如何將圖片放置在控件中的代碼貼出來了。
             
             1 FileOpenPicker^ openPicker = ref new FileOpenPicker();
             2         openPicker->ViewMode = PickerViewMode::Thumbnail;
             3         openPicker->SuggestedStartLocation = PickerLocationId::PicturesLibrary;
             4         openPicker->FileTypeFilter->Append(".jpg");
             5         openPicker->FileTypeFilter->Append(".jpeg");
             6         openPicker->FileTypeFilter->Append(".png");
             7 
             8         create_task(openPicker->PickSingleFileAsync()).then([this,clickedItem](StorageFile^ file)
             9         {
            10             if(file)
            11             {
            12                 create_task(file->OpenAsync(FileAccessMode::Read)).then([this,clickedItem](IRandomAccessStream^ stream)
            13                 {
            14                     
            15                     auto bitmap = ref new BitmapImage();
            16                     bitmap->SetSource(stream);
            17                     clickedItem->Image = bitmap;
            18                 });
            19             }
            20             else
            21             {
            22                 clickedItem->Image = nullptr;
            23             }
            24         });
                 
            這里使用了FilePicker來選擇文件,選擇文件之后,然后打開文件,得到IRandomAccessStream^l流,然后賦值給BitmapImage的源,就可以顯示我們選擇的圖片了。是挺簡單的。感謝一下Draw/C#同學。如果你看到的話,thanks!

            下章提要:如何在Resouce Dictionary中查找Style,并且賦值給控件,今天一直在研究這玩意。C#下好像很容易搞定,但是在C++下怎么就會出現(xiàn)exception呢?已經在MSDN論壇上發(fā)帖問了,希望有個答案。
            posted on 2012-10-23 17:57 Dino-Tech 閱讀(1209) 評論(0)  編輯 收藏 引用 所屬分類: Windows 8
            久久无码AV中文出轨人妻| 伊人久久精品无码av一区| 国产成人精品久久免费动漫| 日韩AV无码久久一区二区| jizzjizz国产精品久久| 国产精品久久永久免费| 国产精品成人精品久久久| 久久久久青草线蕉综合超碰| 国内精品伊人久久久久av一坑| 久久精品国产亚洲Aⅴ香蕉 | 欧美午夜精品久久久久免费视| 亚洲色大成网站WWW久久九九| 狠狠色丁香久久婷婷综| 亚洲日本va午夜中文字幕久久| 日韩人妻无码精品久久久不卡| 丁香久久婷婷国产午夜视频| 久久久久久夜精品精品免费啦| 久久国产精品二国产精品| 欧美噜噜久久久XXX| 亚洲伊人久久成综合人影院 | 99久久亚洲综合精品网站| 亚洲AV伊人久久青青草原| 久久99热只有频精品8| 女人高潮久久久叫人喷水| 国产99久久九九精品无码| 精品国际久久久久999波多野| 无码任你躁久久久久久| 久久激情亚洲精品无码?V| 久久99精品久久久久久| 国产成年无码久久久久毛片| 热99RE久久精品这里都是精品免费| 久久香蕉一级毛片| 精品精品国产自在久久高清| 97久久久精品综合88久久| 久久久国产乱子伦精品作者| 亚洲αv久久久噜噜噜噜噜| 国内精品伊人久久久久777| 伊人色综合久久天天网| 久久亚洲AV无码西西人体| 久久99精品国产麻豆不卡| 精品国产婷婷久久久|