heberoxx 发表于 2015-5-21 09:12:57

win8 app 图片操作(显示缩略图)

  当在metro 程序里面显示一张图片的时候如果这张图片的像素很大 我们就可以先Image控件上显示图片的缩略图 代码如下:
  


uint imageSize = 300;
            FileOpenPicker openPicker = new FileOpenPicker();
            openPicker.ViewMode = PickerViewMode.Thumbnail;
            openPicker.SuggestedStartLocation = PickerLocationId.PicturesLibrary;
            openPicker.FileTypeFilter.Add(".jpg");
            openPicker.FileTypeFilter.Add(".gif");
            openPicker.FileTypeFilter.Add(".png");
            StorageFile file = await openPicker.PickSingleFileAsync();
            if (null != file)
            {
                //缩略图操作
                using (StorageItemThumbnail thumbnail = await file.GetThumbnailAsync(ThumbnailMode.PicturesView, imageSize, ThumbnailOptions.ResizeThumbnail))
                {
                  if (null != thumbnail)
                  {
                        WriteableBitmap bmp = new WriteableBitmap(1,1);
                        bmp.SetSource(thumbnail);
                        bmp.Invalidate();
                        this.image1.Source = bmp;
                  }
                }
            }  
页: [1]
查看完整版本: win8 app 图片操作(显示缩略图)