当前位置: 首页>>代码示例>>C#>>正文


C# BitmapImage.SetSource方法代码示例

本文整理汇总了C#中System.Windows.Media.Imaging.BitmapImage.SetSource方法的典型用法代码示例。如果您正苦于以下问题:C# BitmapImage.SetSource方法的具体用法?C# BitmapImage.SetSource怎么用?C# BitmapImage.SetSource使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在System.Windows.Media.Imaging.BitmapImage的用法示例。


在下文中一共展示了BitmapImage.SetSource方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: GetImage

        public static BitmapImage GetImage(string url)
        {
            // When in design mode of Visual Studio or Blend
            if (ViewModelBase.IsInDesignModeStatic)
            {
                // The image to be returned to the image control
                BitmapImage image = new BitmapImage();
                image.UriSource = new Uri(url);
                return image;
            }

            // Get the filename and path
            string filename = Path.GetFileName(url);
            string fullpath = Path.Combine("Shared", filename);

            // The file doesn't exists.
            // Check if is in the queue to be downloaded.
            if (queue.ContainsKey(fullpath))
            {
                // Return the image associated with this path
                System.Diagnostics.Debug.WriteLine("Exist in cache " + fullpath);
                return queue[fullpath];
            }

            //Try to get the file from isolated storage if it exists, if no it will check in the download queue
            using (IsolatedStorageFile iso = IsolatedStorageFile.GetUserStoreForApplication())
            {
                // The image to be returned to the image control
                BitmapImage image = new BitmapImage();
                Uri uri = new Uri("Icons/ArtPlaceholder.jpg", UriKind.Relative);
                StreamResourceInfo resourceInfo = Application.GetResourceStream(uri);
                image.SetSource(resourceInfo.Stream);

                if (iso.FileExists(fullpath))
                {
                    //The file exists. Read the file and return the stream to the image
                    System.Diagnostics.Debug.WriteLine("Image Loaded from storage " + fullpath);
                    using (IsolatedStorageFileStream stream = iso.OpenFile(fullpath, FileMode.Open))
                    {

                        // The image to be returned to the image control
                        image.SetSource(stream);
                        //queue.Add(url, image);

                    }
                }
                else
                {

                    // It isn't being downloaded.
                    // Download it
                    ImageDownloadHelper.DownloadImage(url, image);
                }   // Save the name in the queue
                queue.Add(fullpath, image);
                return image;
            }
        }
开发者ID:blackjid,项目名称:CouchPotatoWp7,代码行数:57,代码来源:ImageCache.cs

示例2: CachedImage

        public static BitmapImage CachedImage(string Address)
        {
            if (Address == "/Images/Grey.png") { return new BitmapImage(new Uri("/Images/Grey.png", UriKind.Relative)); }
            string ParsedUrl = ParseAddress(Address);

            using (IsolatedStorageFile isolatedStorageFile = IsolatedStorageFile.GetUserStoreForApplication())
            {
                if (isolatedStorageFile.FileExists("imgCache/" + ParsedUrl))
                {
                    try
                    {
                        using (IsolatedStorageFileStream FileStream = IsolatedStorageFile.GetUserStoreForApplication().OpenFile("imgCache\\" + ParsedUrl, FileMode.Open, FileAccess.Read))
                        {
                            BitmapImage _Bitmap = new BitmapImage();
                            _Bitmap.SetSource(FileStream);
                            return _Bitmap;
                        }
                    }
                    catch
                    {
                        BitmapImage _Bitmap = new BitmapImage();
                        _Bitmap.ImageOpened += CachedImageOpened;
                        _Bitmap.UriSource = new Uri(Address, UriKind.RelativeOrAbsolute);
                        return _Bitmap;
                    }
                }
                else
                {
                    BitmapImage _Bitmap = new BitmapImage();
                    _Bitmap.ImageOpened += CachedImageOpened;
                    _Bitmap.UriSource = new Uri(Address, UriKind.RelativeOrAbsolute);
                    return _Bitmap;
                }
            }
        }
开发者ID:CrisRowlands,项目名称:FSF,代码行数:35,代码来源:ImageManager.cs

示例3: OnNavigatedTo

        protected override void OnNavigatedTo(NavigationEventArgs e)
        {
            base.OnNavigatedTo(e);

            if (e.NavigationMode == NavigationMode.New)
            {
                XElement article = XElement.Load("Resources/about_program.xml");

                XElement Credits = article.Element("Credits");
                CreditsAbout.Text = Credits.Element("text").Value;

                CreditsCopyright.Text = "\u00A9" + CreditsCopyright.Text;
                CreditsText.Content = "\"" + CreditsText.Content + "\"";

                Version.Text = AppResources.Version + ": " + article.Element("version").Value;

                XElement developer = article.Element("developer");
                Stream stream = Application.GetResourceStream(new Uri(developer.Element("logo").Attribute("src").Value, UriKind.Relative)).Stream;

                BitmapImage bmp = new BitmapImage();
                bmp.SetSource(stream);
                stream.Close();

                DeveloperLogo.Source = bmp;
                DeveloperLogo.Stretch = Stretch.Uniform;
            }
        }
开发者ID:ershovdz,项目名称:MobileCreditBroker,代码行数:27,代码来源:AboutProgramView.xaml.cs

示例4: ByteArraytoBitmap

 public static BitmapImage ByteArraytoBitmap(Byte[] byteArray)
 {
     MemoryStream stream = new MemoryStream(byteArray);
     BitmapImage bitmapImage = new BitmapImage();
     bitmapImage.SetSource(stream);
     return bitmapImage;
 }
开发者ID:Grief-Code,项目名称:kilogram,代码行数:7,代码来源:ImageByteArrayAttachedProperty.cs

示例5: PopulateImageGrid

        private void PopulateImageGrid()
        {
            MediaLibrary mediaLibrary = new MediaLibrary();
            var pictures = mediaLibrary.Pictures;

            for (int i = 0; i < pictures.Count; i += Utilities.ImagesPerRow)
            {
                RowDefinition rd = new RowDefinition();
                rd.Height = new GridLength(Utilities.GridRowHeight);
                grid1.RowDefinitions.Add(rd);

                int maxPhotosToProcess = (i + Utilities.ImagesPerRow < pictures.Count ? i + Utilities.ImagesPerRow : pictures.Count);
                int rowNumber = i / Utilities.ImagesPerRow;
                for (int j = i; j < maxPhotosToProcess; j++)
                {
                    BitmapImage image = new BitmapImage();
                    image.SetSource(pictures[j].GetImage());

                    Image img = new Image();
                    img.Height = Utilities.ImageHeight;
                    img.Stretch = Stretch.Fill;
                    img.Width = Utilities.ImageWidth;
                    img.HorizontalAlignment = HorizontalAlignment.Center;
                    img.VerticalAlignment = VerticalAlignment.Center;
                    img.Source = image;
                    img.SetValue(Grid.RowProperty, rowNumber);
                    img.SetValue(Grid.ColumnProperty, j - i);
                    img.Tap += Image_Tap;
                    grid1.Children.Add(img);
                }
            }
        }
开发者ID:tiagobabo,项目名称:windows-phone-gallery,代码行数:32,代码来源:LocalStorage.xaml.cs

示例6: DownloadImageCallback

        public static void DownloadImageCallback(IAsyncResult result)
        {
            try
            {
                HttpWebRequest req = (HttpWebRequest)result.AsyncState;
                HttpWebResponse responce = (HttpWebResponse)req.EndGetResponse(result);
                Stream stream = responce.GetResponseStream();

                string fileName = Path.GetFileName(responce.ResponseUri.AbsoluteUri.ToString());

                Deployment.Current.Dispatcher.BeginInvoke(() =>
                {
                    BitmapImage bmp = new BitmapImage();
                    bmp.SetSource(stream);
                    if (!IsolatedStorageHelper.isFileAlreadySaved(responce.ResponseUri.AbsoluteUri.ToString()))
                    {
                        IsolatedStorageHelper.saveImage(bmp, fileName);
                    }
                });
                addDownloadedItemsToFilmCollection(responce.ResponseUri.AbsoluteUri.ToString());
            }
            catch (System.Net.WebException e)
            {
                Deployment.Current.Dispatcher.BeginInvoke(() =>
                {
                    MessageBox.Show(e.Message.ToString());
                });
            }
        }
开发者ID:asdForever,项目名称:TouchInstinctTestApp,代码行数:29,代码来源:ImageHelper.cs

示例7: Convert

 public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
 {
     try
     {
         BitmapImage img = new BitmapImage();
         string filePath = (string)value;
         using (IsolatedStorageFile isf = IsolatedStorageFile.GetUserStoreForApplication())
         {
             if (isf.FileExists(filePath))
             {
                 using (IsolatedStorageFileStream stream = isf.OpenFile(filePath, FileMode.Open, FileAccess.Read))
                 {
                     img.SetSource(stream);
                 }
             }
             else
             {
                 img = null;
             }
         }
         return img;
     }
     catch (Exception ex)
     {
         MessageBox.Show(ex.Message);
         return null;
     }
 }
开发者ID:arcsinW,项目名称:zhangkong,代码行数:28,代码来源:StringToImageSource.cs

示例8: PhoneApplicationPage_Loaded

        private void PhoneApplicationPage_Loaded(object sender, RoutedEventArgs e)
        {

            if (a != null)
            {
                textBox1.Text = string.Format("这个有意思 →_→【{0}】{1}(分享自 @果壳网)", a.title, a.wwwurl);
                if (!string.IsNullOrEmpty(a.pic))
                {
                    string large_pic_uri = a.pic.Replace("/img2.", "/img1.").Replace("thumbnail", "gkimage").Replace("_90", "");

                    var large_uri = new Uri(large_pic_uri, UriKind.Absolute);
                    var _imgsrc = new BitmapImage();
                    WebClient wc = new WebClient();
                    wc.Headers["Referer"] = "http://www.guokr.com";
                    wc.OpenReadCompleted += (s, ee) =>
                        {
                            try
                            {
                                _imgsrc.SetSource(ee.Result);
                            }
                            catch
                            {

                            }
                        };
                    wc.OpenReadAsync(large_uri);
                    _imgsrc.ImageFailed += (ss, ee) => _imgsrc.UriSource = new Uri(a.pic, UriKind.Absolute);
                    image_preview.Source = _imgsrc;
                }
            }

            sending_popup.Visibility = System.Windows.Visibility.Collapsed;
        }
开发者ID:oxcsnicho,项目名称:SanzaiGuokr,代码行数:33,代码来源:WeiboCreate.xaml.cs

示例9: EditPage

        public EditPage()
        {
            InitializeComponent();
            BitmapImage bi = new BitmapImage();
            using (var store = IsolatedStorageFile.GetUserStoreForApplication())
            {
                /*var filestream = store.OpenFile("image.jpg", System.IO.FileMode.Open, System.IO.FileAccess.Read);
                var imageAsBitmap = Microsoft.Phone.PictureDecoder.DecodeJpeg(filestream);
                image2.Source = imageAsBitmap;
                */
                if (store.FileExists("tempJPEG2"))
                {
                    using (IsolatedStorageFileStream fileStream = store.OpenFile("tempJPEG2", System.IO.FileMode.Open, System.IO.FileAccess.Read))
                    {
                        bi.SetSource(fileStream);
                        image2.Source = bi;
                    }
                }
                else
                {
                    var filestream = store.OpenFile("image.jpg", System.IO.FileMode.Open, System.IO.FileAccess.Read);
                    var imageAsBitmap = Microsoft.Phone.PictureDecoder.DecodeJpeg(filestream);
                    image2.Source = imageAsBitmap;
                }
            }

        }
开发者ID:aabrohi,项目名称:kinect-kollage,代码行数:27,代码来源:EditPage.xaml.cs

示例10: LoadImage

 public static BitmapSource LoadImage(string imageName)
 {
     StreamResourceInfo resourceInfo = Application.GetResourceStream(new Uri("Core;component/resources/" + imageName, UriKind.Relative));
       var image = new BitmapImage();
       image.SetSource(resourceInfo.Stream);
       return image;
 }
开发者ID:valentinkip,项目名称:Test,代码行数:7,代码来源:Images.cs

示例11: MaskedBitmapImage

 public MaskedBitmapImage(Stream selectedImage, String relativeUrl)
 {
     BitmapImage source = new BitmapImage();
     source.SetSource(selectedImage);
     this.source = source;
     ChangeMask(relativeUrl);
 }
开发者ID:BlakeBarrett,项目名称:mskr-windows-phone,代码行数:7,代码来源:MaskedBitmapImage.cs

示例12: SetImage

 private void SetImage(int index)
 {
     var refPic = App.ViewModel.Pictures[index].Id;
     var bitmap = new BitmapImage();
     bitmap.SetSource(refPic.GetImage());
     FullPicture.Source = bitmap;
 }
开发者ID:joekickass,项目名称:winphone-picture-tagging,代码行数:7,代码来源:SelectedPicturePage.xaml.cs

示例13: ColorClient_FrameReady

		void ColorClient_FrameReady(object sender, FrameReadyEventArgs e)
		{
			MemoryStream ms = new MemoryStream(e.Data);
			BinaryReader br = new BinaryReader(ms);

			ColorFrameReadyEventArgs args = new ColorFrameReadyEventArgs();
			ColorFrameData cfd = new ColorFrameData
			{
				Format = (ImageFormat)br.ReadInt32(),
				ImageFrame = br.ReadColorImageFrame()
			};

			if(cfd.Format == ImageFormat.Raw)
			    cfd.RawImage = br.ReadBytes(e.Data.Length - sizeof(bool));
			else
			{
				BitmapImage bi = new BitmapImage();
				bi.SetSource(new MemoryStream(e.Data, (int)ms.Position, (int)(ms.Length - ms.Position)));
				cfd.BitmapImage = bi;
			}

			ColorFrame = cfd;
			args.ColorFrame = cfd;

			if(ColorFrameReady != null)
				ColorFrameReady(this, args);
		}
开发者ID:Cocotus,项目名称:kinect,代码行数:27,代码来源:ColorClient.cs

示例14: EditorPage

        public EditorPage()
        {
            InitializeComponent();
            if (DataSystem.ChosenPhoto != null)
            {
                BitmapImage bitmapImagePreview = new BitmapImage();
                bitmapImagePreview.SetSource(DataSystem.ChosenPhotoPreview);
                DataSystem.RenderedPreview = new WriteableBitmap(bitmapImagePreview);

                imgMain.Source = DataSystem.RenderedPreview;

                foreach (String effStr in _effStrList)
                {
                    EffectElement t = new EffectElement();

                    t.SetEffectString(effStr);
                    t.UpdateEffectImage();

                    effList.Children.Add(t);
                }
                DataSystem.RenderedPreview = new WriteableBitmap(bitmapImagePreview.PixelWidth, bitmapImagePreview.PixelHeight);

                BitmapImage bitmapImageThumbnail = new BitmapImage();
                bitmapImageThumbnail.SetSource(DataSystem.ChosenPhotoThumbnailOrigin);

                DataSystem.RenderedThumbnail = new WriteableBitmap(bitmapImageThumbnail.PixelWidth, bitmapImageThumbnail.PixelHeight);
            }
        }
开发者ID:nguoihocnghe,项目名称:TypoQuote,代码行数:28,代码来源:EditorPage.xaml.cs

示例15: OnNavigatedTo

        protected override void OnNavigatedTo(NavigationEventArgs e)
        {
            base.OnNavigatedTo(e);
            StackPanel grid = (LayoutRoot.FindName("PhotoViewer") as StackPanel);

            using (IsolatedStorageFile isStore = IsolatedStorageFile.GetUserStoreForApplication())
            {
                if(isStore.DirectoryExists("files"))
                {
                    string[] fileNames = isStore.GetFileNames("files/*.jpg");
                    foreach (string fileName in fileNames)
                    {
            //                    TextBlock block = new TextBlock();
            //                    block.Text = fileName;
            //                    grid.Children.Add(block);

                        Button button = new Button();
                        button.Content = fileName;
                        button.VerticalContentAlignment = System.Windows.VerticalAlignment.Bottom;
                        ImageBrush brush = new ImageBrush();
                        BitmapImage bi = new BitmapImage();
                        bi.SetSource(isStore.OpenFile("files\\"+fileName, FileMode.Open, FileAccess.Read));
                        brush.ImageSource = bi;
                        brush.Stretch = Stretch.Uniform;
                        button.Height = 300;
                        button.Width = 300;
                        button.Background = brush;

                        grid.Children.Add(button);
                    }
                }
            }
        }
开发者ID:HKMOpen,项目名称:innovativeproject-meetingdataexchange,代码行数:33,代码来源:ViewFilesPage.xaml.cs


注:本文中的System.Windows.Media.Imaging.BitmapImage.SetSource方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。