當前位置: 首頁>>代碼示例>>C#>>正文


C# BitmapImage.SetSource方法代碼示例

本文整理匯總了C#中Windows.UI.Xaml.Media.Imaging.BitmapImage.SetSource方法的典型用法代碼示例。如果您正苦於以下問題:C# BitmapImage.SetSource方法的具體用法?C# BitmapImage.SetSource怎麽用?C# BitmapImage.SetSource使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在Windows.UI.Xaml.Media.Imaging.BitmapImage的用法示例。


在下文中一共展示了BitmapImage.SetSource方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的C#代碼示例。

示例1: OnCapturePhotoButtonClick

        private async void OnCapturePhotoButtonClick(object sender, RoutedEventArgs e)
        {
            var file = await TestedControl.CapturePhotoToStorageFileAsync(ApplicationData.Current.TemporaryFolder);
            var bi = new BitmapImage();

            IRandomAccessStreamWithContentType stream;

            try
            {
                stream = await TryCatchRetry.RunWithDelayAsync<Exception, IRandomAccessStreamWithContentType>(
                    file.OpenReadAsync(),
                    TimeSpan.FromSeconds(0.5),
                    10,
                    true);
            }
            catch (Exception ex)
            {
                // Seems like a bug with WinRT not closing the file sometimes that writes the photo to.
#pragma warning disable 4014
                new MessageDialog(ex.Message, "Error").ShowAsync();
#pragma warning restore 4014

                return;
            }

            bi.SetSource(stream);
            PhotoImage.Source = bi;
            CapturedVideoElement.Visibility = Visibility.Collapsed;
            PhotoImage.Visibility = Visibility.Visible;
        }
開發者ID:prabaprakash,項目名稱:Visual-Studio-2013,代碼行數:30,代碼來源:CameraCaptureControlPage.xaml.cs

示例2: ButtonCamera_Click

        private async void ButtonCamera_Click(object sender, RoutedEventArgs e)
        {
            CameraCaptureUI captureUI = new CameraCaptureUI();
            captureUI.PhotoSettings.Format = CameraCaptureUIPhotoFormat.Jpeg;
            captureUI.PhotoSettings.CroppedSizeInPixels = new Size(600, 600);

            StorageFile photo = await captureUI.CaptureFileAsync(CameraCaptureUIMode.Photo);

            if (photo != null)
            {
                BitmapImage bmp = new BitmapImage();
                IRandomAccessStream stream = await photo.
                                                   OpenAsync(FileAccessMode.Read);
                bmp.SetSource(stream);
                BBQImage.Source = bmp;

                FileSavePicker savePicker = new FileSavePicker();
                savePicker.FileTypeChoices.Add
                                      ("jpeg image", new List<string>() { ".jpeg" });

                savePicker.SuggestedFileName = "New picture";

                StorageFile savedFile = await savePicker.PickSaveFileAsync();

                (this.DataContext as BBQRecipeViewModel).imageSource = savedFile.Path;

                if (savedFile != null)
                {
                    await photo.MoveAndReplaceAsync(savedFile);
                }
            }
        }
開發者ID:cheahengsoon,項目名稱:Windows10UWP-HandsOnLab,代碼行數:32,代碼來源:BBQRecipePage.xaml.cs

示例3: Add_image

        private async void Add_image(object sender, RoutedEventArgs e)
        {
            FileOpenPicker fp = new FileOpenPicker();

            // Adding filters for the file type to access.
            fp.FileTypeFilter.Add(".jpeg");
            fp.FileTypeFilter.Add(".png");
            fp.FileTypeFilter.Add(".bmp");
            fp.FileTypeFilter.Add(".jpg");

            // Using PickSingleFileAsync() will return a storage file which can be saved into an object of storage file class.

            StorageFile sf = await fp.PickSingleFileAsync();

            // Adding bitmap image object to store the stream provided by the object of StorageFile defined above.
            BitmapImage bmp = new BitmapImage();

            // Reading file as a stream and saving it in an object of IRandomAccess.
            IRandomAccessStream stream = await sf.OpenAsync(FileAccessMode.Read);

            // Adding stream as source of the bitmap image object defined above
            bmp.SetSource(stream);

            // Adding bmp as the source of the image in the XAML file of the document.
            image.Source = bmp;
        }
開發者ID:sarthakbhol,項目名稱:Windows10AppSamples,代碼行數:26,代碼來源:MainPage.xaml.cs

示例4: Activate

        /// <summary>
        /// Invoked when another application wants to share content through this application.
        /// </summary>
        /// <param name="args">Activation data used to coordinate the process with Windows.</param>
        public async void Activate(ShareTargetActivatedEventArgs args)
        {
            this._shareOperation = args.ShareOperation;
            

            // Communicate metadata about the shared content through the view model
            var shareProperties = this._shareOperation.Data.Properties;
            var thumbnailImage = new BitmapImage();
            this.DefaultViewModel["Title"] = shareProperties.Title;
            this.DefaultViewModel["Description"] = shareProperties.Description;
            this.DefaultViewModel["Image"] = thumbnailImage;
            this.DefaultViewModel["Sharing"] = false;
            this.DefaultViewModel["ShowImage"] = false;
            this.DefaultViewModel["Comment"] = String.Empty;
            this.DefaultViewModel["SupportsComment"] = true;
            Window.Current.Content = this;
            Window.Current.Activate();

            Detector dt = new Detector(_shareOperation.Data);
            dt.Detect();
            this.DataContext = dt.Detected;

            // Update the shared content's thumbnail image in the background
            if (shareProperties.Thumbnail != null)
            {
                var stream = await shareProperties.Thumbnail.OpenReadAsync();
                thumbnailImage.SetSource(stream);
                this.DefaultViewModel["ShowImage"] = true;
            }
        }
開發者ID:Tadimsky,項目名稱:MSAppHack,代碼行數:34,代碼來源:SharePage.xaml.cs

示例5: Convert

        public object Convert(object value, Type targetType, object parameter, string language)
        {
            if (value != null)
            {

                byte[] bytes = (byte[])value;
                BitmapImage myBitmapImage = new BitmapImage();
                if (bytes.Count() > 0)
                {


                    InMemoryRandomAccessStream stream = new InMemoryRandomAccessStream();
                    DataWriter writer = new DataWriter(stream.GetOutputStreamAt(0));

                    writer.WriteBytes(bytes);
                    writer.StoreAsync().GetResults();
                    myBitmapImage.SetSource(stream);
                }
                else
                {
                    myBitmapImage.UriSource = new Uri("ms-appx:///Assets/firstBackgroundImage.jpg");
                }

                return myBitmapImage;
            }
            else
            {
                return new BitmapImage();
            }
        }
開發者ID:garicchi,項目名稱:Neuronia,代碼行數:30,代碼來源:ByteToBitmapConverterForBackground.cs

示例6: GetBitmapAsync

 public async Task<Windows.UI.Xaml.Media.Imaging.BitmapImage> GetBitmapAsync()
 {
     var image = new Windows.UI.Xaml.Media.Imaging.BitmapImage();
     stream.Seek(0);
     image.SetSource(stream);
     return image;
 }
開發者ID:kurema,項目名稱:BookViewerApp,代碼行數:7,代碼來源:BookImage.cs

示例7: GetPhotoInDevice

        public static async Task<List<LocationData>> GetPhotoInDevice()
        {
            List<LocationData> mapPhotoIcons = new List<LocationData>();
            IReadOnlyList<StorageFile> photos = await KnownFolders.CameraRoll.GetFilesAsync();
            for (int i = 0; i < photos.Count; i++)
            {

                Geopoint geopoint = await GeotagHelper.GetGeotagAsync(photos[i]);
                if (geopoint != null)
                {
                    //should use Thumbnail to reduce the size of images, otherwise low-end device will crashes
                    var fileStream = await photos[i].GetThumbnailAsync(ThumbnailMode.PicturesView);
                    var img = new BitmapImage();
                    img.SetSource(fileStream);


                    mapPhotoIcons.Add(new LocationData
                    {
                        Position = geopoint.Position,
                        DateCreated = photos[i].DateCreated,
                        ImageSource = img
                    });
                }
            }
            var retMapPhotos = mapPhotoIcons.OrderBy(x => x.DateCreated).ToList();

            return retMapPhotos;
        }
開發者ID:ngducnghia,項目名稱:TripTrak,代碼行數:28,代碼來源:PhotoHelper.cs

示例8: GetPictureFromGalleryAsync

        public async Task<string> GetPictureFromGalleryAsync()
		{
            FileOpenPicker openPicker = new FileOpenPicker
            {
                ViewMode = PickerViewMode.Thumbnail,
                SuggestedStartLocation = PickerLocationId.PicturesLibrary
            };
            openPicker.FileTypeFilter.Add(".jpg");
            openPicker.FileTypeFilter.Add(".jpeg");
            openPicker.FileTypeFilter.Add(".bmp");
            openPicker.FileTypeFilter.Add(".png");

            StorageFile file = await openPicker.PickSingleFileAsync();
            if (file != null)
            {
                var stream = await file.OpenAsync(FileAccessMode.Read);
                BitmapImage image = new BitmapImage();
                image.SetSource(stream);

                var path = Path.Combine(StorageService.ImagePath);
                _url = String.Format("Image_{0}.{1}", Guid.NewGuid(), file.FileType);
                var folder = await StorageFolder.GetFolderFromPathAsync(path);

                //TODO rajouter le code pour le redimensionnement de l'image

                await file.CopyAsync(folder, _url);
                return string.Format("{0}\\{1}", path, _url);
            }

            return "";
		}
開發者ID:india-rose,項目名稱:xamarin-indiarose,代碼行數:31,代碼來源:MediaService.cs

示例9: GetImageForId

        private async Task<BitmapImage> GetImageForId(string id)
        {

            var contactStore = await ContactManager.RequestStoreAsync();
            var contact = await contactStore.GetContactAsync(id);

            if (contact.Thumbnail == null)
            {
                BitmapImage image = new BitmapImage();
                image.DecodePixelHeight = 100;
                image.DecodePixelWidth = 100;

                return image;
            }

            using (var stream = await contact.Thumbnail.OpenReadAsync())
            {

                BitmapImage image = new BitmapImage();
                image.DecodePixelHeight = 100;
                image.DecodePixelWidth = 100;

                image.SetSource(stream);

                return image;
            }
        }
開發者ID:smndtrl,項目名稱:Signal-UWP,代碼行數:27,代碼來源:ContactPictureConverter.cs

示例10: DisplayStorageFileAsync

        private async Task DisplayStorageFileAsync(StorageFile storageFile)
        {
            var bitmapImage = new BitmapImage();
            bitmapImage.SetSource(await _storageFile.OpenAsync(FileAccessMode.Read));

            ImagePhoto.Source = bitmapImage;
        }
開發者ID:hwangtamu,項目名稱:flickr-sdk,代碼行數:7,代碼來源:MainPage.xaml.cs

示例11: clickbtn_Click

        private async void clickbtn_Click(object sender, RoutedEventArgs e)
        {
            FolderPicker fp = new FolderPicker();
            fp.SuggestedStartLocation = PickerLocationId.PicturesLibrary;
            fp.ViewMode = PickerViewMode.Thumbnail;
            fp.FileTypeFilter.Add(".jpg");
            fp.FileTypeFilter.Add(".png");
            fp.FileTypeFilter.Add(".jpeg");
            var file = await fp.PickSingleFolderAsync();
            fl = await file.GetFilesAsync();
            if (file != null)
            {
                StorageFile sf = fl[0];
                foreach (StorageFile images in fl)
                {
                    IRandomAccessStream str = await images.OpenAsync(FileAccessMode.Read);
                    BitmapImage bitmapimage = new BitmapImage();
                    bitmapimage.SetSource(str);

                    fp1.Items.Add(bitmapimage);
                 

                 
                }
        
            }

        }
開發者ID:Bhargavi-Chirukuri,項目名稱:folder,代碼行數:28,代碼來源:MainPage.xaml.cs

示例12: LoadPicture

        public async Task LoadPicture(Favourite photo)
        {
            
            try
            {

                layoutRoot.DataContext = photo;

                var folder = await Windows.Storage.KnownFolders.PicturesLibrary.GetFolderAsync("ModernCSApp");
                var file = await folder.GetFileAsync(photo.AggregateId.Replace("-","") + ".jpg");

                using (var stream = await file.OpenReadAsync())
                {
                    BitmapImage bi = new BitmapImage();
                    bi.SetSource(stream);
                    imgMain.Source = bi;

                }

                grdPhotoQuickDetails.Visibility = Windows.UI.Xaml.Visibility.Visible;
                
                if (photo.MediaTitle != string.Empty) grdPhotoQuickDetailsTop.Visibility = Windows.UI.Xaml.Visibility.Visible;
                else grdPhotoQuickDetailsTop.Visibility = Visibility.Collapsed;

                //imgMain.Source = bi;
                if (ChangeViewState != null) ChangeViewState("Normal", null);
            }
            catch
            {

            }
        }
開發者ID:rolandsmeenk,項目名稱:ModernApps,代碼行數:32,代碼來源:Picture.xaml.cs

示例13: Convert

        public object Convert(object value, Type targetType, object parameter, string language)
        {
            if (value != null && value is byte[])
            {

                //WriteableBitmap bitmap = new WriteableBitmap(100, 100);

                //System.IO.Stream bitmapStream = null;
                //bitmapStream = bitmap.PixelBuffer.AsStream();
                //bitmapStream.Position = 0;
                //bitmapStream.Write(value as byte[], 0, (value as byte[]).Length);

                //bitmapStream.Flush();

                InMemoryRandomAccessStream randomAccessStream = new InMemoryRandomAccessStream();
                DataWriter writer = new DataWriter(randomAccessStream.GetOutputStreamAt(0));
                writer.WriteBytes(value as byte[]);
                var x = writer.StoreAsync().AsTask().Result;
                BitmapImage image = new BitmapImage();
                image.SetSource(randomAccessStream);

                return image;
            }

            return null;
        }
開發者ID:garymedina,項目名稱:MyEvents,代碼行數:26,代碼來源:ByteToImageConverter.cs

示例14: Convert

        public object Convert(object value, Type targetType, object parameter, string language)
        {
            BitmapImage image = null;

            if (value != null)
            {
                if (value.GetType() != typeof(FileRandomAccessStream))
                {
                    throw new ArgumentException("Expected a StorageItemThumbnail as binding input.");
                }
                if (targetType != typeof(ImageSource))
                {
                    throw new ArgumentException("Expected ImageSource as binding output.");
                }

                if ((FileRandomAccessStream)value == null)
                {
                    return image;
                }

                image = new BitmapImage();

                using (var thumbNailClonedStream = ((FileRandomAccessStream)value).CloneStream())
                    image.SetSource(thumbNailClonedStream);
            }

            return (image);
        }
開發者ID:RareNCool,項目名稱:EPubReader,代碼行數:28,代碼來源:RasToImageSourceConverter.cs

示例15: GetSmallImageButton_Click

        private async void GetSmallImageButton_Click(object sender, RoutedEventArgs e)
        {
            // The small picture returned by GetAccountPicture() is 96x96 pixels in size.
            StorageFile image = UserInformation.GetAccountPicture(AccountPictureKind.SmallImage) as StorageFile;
            if (image != null)
            {
                rootPage.NotifyUser("SmallImage path = " + image.Path, NotifyType.StatusMessage);

                try
                {
                    IRandomAccessStream imageStream = await image.OpenReadAsync();
                    BitmapImage bitmapImage = new BitmapImage();
                    bitmapImage.SetSource(imageStream);
                    smallImage.Source = bitmapImage;

                    smallImage.Visibility = Visibility.Visible;
                    largeImage.Visibility = Visibility.Collapsed;
                    mediaPlayer.Visibility = Visibility.Collapsed;
                }
                catch (Exception ex)
                {
                    rootPage.NotifyUser("Error opening stream: " + ex.ToString(), NotifyType.ErrorMessage);
                }
            }
            else
            {
                rootPage.NotifyUser("Small Account Picture is not available", NotifyType.StatusMessage);
                mediaPlayer.Visibility = Visibility.Collapsed;
                smallImage.Visibility = Visibility.Collapsed;
                largeImage.Visibility = Visibility.Collapsed;
            }
        }
開發者ID:oldnewthing,項目名稱:old-Windows8-samples,代碼行數:32,代碼來源:GetAccountPicture.xaml.cs


注:本文中的Windows.UI.Xaml.Media.Imaging.BitmapImage.SetSource方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。