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


C# Imaging.BitmapImage类代码示例

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


BitmapImage类属于Windows.UI.Xaml.Media.Imaging命名空间,在下文中一共展示了BitmapImage类的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: Base64ToBitmapImage

        public async Task<BitmapImage> Base64ToBitmapImage(string base64String)
        {

            BitmapImage img = new BitmapImage();
            if (string.IsNullOrEmpty(base64String))
                return img;

            using (var ims = new InMemoryRandomAccessStream())
            {
                byte[] bytes = Convert.FromBase64String(base64String);
                base64String = "";

                using (DataWriter dataWriter = new DataWriter(ims))
                {
                    dataWriter.WriteBytes(bytes);
                    bytes = null;
                    await dataWriter.StoreAsync();
                                 

                ims.Seek(0);

              
               await img.SetSourceAsync(ims); //not in RC
               
               
                return img;
                }
            }

        }
开发者ID:bdecori,项目名称:win8,代码行数:30,代码来源:Utility.cs

示例4: EditCurrentImage

 public EditCurrentImage(Image source, int sentId, BitmapImage sentSrc)
 {
     img = source;
     currentAngle = 0;
     id = sentId;
     bmp = sentSrc;
 }
开发者ID:tupakk,项目名称:dat210-gruppeb,代码行数:7,代码来源:EditCurrentImage.cs

示例5: ImageFromRelativePath

 public static BitmapImage ImageFromRelativePath(FrameworkElement parent, string path)
 {
     var uri = new Uri(parent.BaseUri, path);
     BitmapImage result = new BitmapImage();
     result.UriSource = uri;
     return result;
 }
开发者ID:RodionXedin,项目名称:Game1-TowerDefence,代码行数:7,代码来源:Game.cs

示例6: 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

示例7: PerformFaceAnalysis

        private async void PerformFaceAnalysis(StorageFile file)
        {
            var imageInfo = await FileHelper.GetImageInfoForRendering(file.Path);
            NewImageSizeWidth = 300;
            NewImageSizeHeight = NewImageSizeWidth*imageInfo.Item2/imageInfo.Item1;

            var newSourceFile = await FileHelper.CreateCopyOfSelectedImage(file);
            var uriSource = new Uri(newSourceFile.Path);
            SelectedFileBitmapImage = new BitmapImage(uriSource);


            // start face api detection
            var faceApi = new FaceApiHelper();
            DetectedFaces = await faceApi.StartFaceDetection(newSourceFile.Path, newSourceFile, imageInfo, "4c138b4d82b947beb2e2926c92d1e514");

            // draw rectangles 
            var color = Color.FromArgb(125, 255, 0, 0);
            var bg = new SolidColorBrush(color);

            DetectedFacesCanvas = new ObservableCollection<Canvas>();
            foreach (var detectedFace in DetectedFaces)
            {
                var margin = new Thickness(detectedFace.RectLeft, detectedFace.RectTop, 0, 0);
                var canvas = new Canvas()
                {
                    Background = bg,
                    HorizontalAlignment = HorizontalAlignment.Left,
                    VerticalAlignment = VerticalAlignment.Top,
                    Height = detectedFace.RectHeight,
                    Width = detectedFace.RectWidth,
                    Margin = margin
                };
                DetectedFacesCanvas.Add(canvas);
            }
        }
开发者ID:modulexcite,项目名称:ProjectOxford,代码行数:35,代码来源:MainPage.xaml.cs

示例8: TileToImage

 public static async Task<BitmapImage> TileToImage(byte[] tile)
 {
     var image = await ByteArrayToRandomAccessStream(tile);
     var bitmapImage = new BitmapImage();
     bitmapImage.SetSource(image);
     return bitmapImage;
 }
开发者ID:galchen,项目名称:brutile,代码行数:7,代码来源:Utilities.cs

示例9: LoadData

        public async void LoadData(IEnumerable<XElement> sprites, StorageFile spriteSheetFile, string appExtensionId)
        {
            var bitmapImage = new BitmapImage();
            using (var stream = await spriteSheetFile.OpenReadAsync()) {
                await bitmapImage.SetSourceAsync(stream);
            }
            
            //xaml
            List<ImageListItem> listOfImages = new List<ImageListItem>();
            foreach (var sprite in sprites) {
                var row = int.Parse(sprite.Attributes("Row").First().Value);
                var col = int.Parse(sprite.Attributes("Column").First().Value);

                var brush = new ImageBrush();
                brush.ImageSource = bitmapImage;
                brush.Stretch = Stretch.UniformToFill;
                brush.AlignmentX = AlignmentX.Left;
                brush.AlignmentY = AlignmentY.Top;
                brush.Transform = new CompositeTransform() { ScaleX = 2.35, ScaleY = 2.35, TranslateX = col * (-140), TranslateY = row * (-87) };
                listOfImages.Add(new ImageListItem() {
                    Title = sprite.Attributes("Title").First().Value,
                    SpriteSheetBrush = brush,
                    File = sprite.Attributes("File").First().Value,
                    AppExtensionId = appExtensionId
                });
            }
            lbPictures.ItemsSource = listOfImages;
        }
开发者ID:liquidboy,项目名称:X,代码行数:28,代码来源:ImagePicker.xaml.cs

示例10: 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

示例11: GetUserThumbnailPhotoAsync

        /// <summary>
        /// Get the user's photo.
        /// </summary>
        /// <param name="user">The target user.</param>
        /// <returns></returns>
        public async Task<BitmapImage> GetUserThumbnailPhotoAsync(IUser user)
        {
            BitmapImage bitmap = null;
            try
            {
                // The using statement ensures that Dispose is called even if an 
                // exception occurs while you are calling methods on the object.
                using (var dssr = await user.ThumbnailPhoto.DownloadAsync())
                using (var stream = dssr.Stream)
                using (var memStream = new MemoryStream())
                {
                    await stream.CopyToAsync(memStream);
                    memStream.Seek(0, SeekOrigin.Begin);
                    bitmap = new BitmapImage();
                    await bitmap.SetSourceAsync(memStream.AsRandomAccessStream());
                }

            }
            catch(ODataException)
            {
                // Something went wrong retrieving the thumbnail photo, so set the bitmap to a default image
                bitmap = new BitmapImage(new Uri("ms-appx:///assets/UserDefaultSignedIn.png", UriKind.RelativeOrAbsolute));
            }

            return bitmap;
        }
开发者ID:delacruzjayveejoshua920,项目名称:ICNG-App-for-Windows-8.1-and-Windows-Phone-8.1-,代码行数:31,代码来源:UserOperations.cs

示例12: BackgroundButton_Click

      private async void BackgroundButton_Click(object sender, RoutedEventArgs e)
      {
        // Clear previous returned file name, if it exists, between iterations of this scenario
        OutputTextBlock.Text = "";

        FileOpenPicker openPicker = new FileOpenPicker();
        openPicker.ViewMode = PickerViewMode.Thumbnail;
        openPicker.SuggestedStartLocation = PickerLocationId.PicturesLibrary;
        openPicker.FileTypeFilter.Add(".jpg");
        openPicker.FileTypeFilter.Add(".jpeg");
        openPicker.FileTypeFilter.Add(".png");
        StorageFile file = await openPicker.PickSingleFileAsync();
        if (file != null)
        {
          // Application now has read/write access to the picked file
          OutputTextBlock.Text = "Picked photo: " + file.Name;

          BitmapImage img = new BitmapImage();
          img = await ImageHelpers.LoadImage( file );
          MyPicture.Source = img;

        }
        else
        {
          OutputTextBlock.Text = "Operation cancelled.";
        }
      }
开发者ID:underhilld2,项目名称:BedSideClock,代码行数:27,代码来源:StartupPage.xaml.cs

示例13: GetImage

        public static BitmapImage GetImage(string path, bool negateResult = false)
        {
            if (string.IsNullOrEmpty(path))
            {
                return null;
            }

            var isDarkTheme = Application.Current.RequestedTheme == ApplicationTheme.Dark;

            if (negateResult)
            {
                isDarkTheme = !isDarkTheme;
            }

            BitmapImage result;
            path = "ms-appx:" + string.Format(path, isDarkTheme ? "dark" : "light");

            // Check if we already cached the image
            if (!ImageCache.TryGetValue(path, out result))
            {
                result = new BitmapImage(new Uri(path, UriKind.Absolute));
                ImageCache.Add(path, result);
            }

            return result;
        }
开发者ID:gitter-badger,项目名称:MoneyManager,代码行数:26,代码来源:ThemedImageConverterLogic.cs

示例14: Activate

        /// <summary>
        /// 他のアプリケーションがこのアプリケーションを介してコンテンツの共有を求めた場合に呼び出されます。
        /// </summary>
        /// <param name="args">Windows と連携して処理するために使用されるアクティベーション データ。</param>
        public async void Activate(ShareTargetActivatedEventArgs args)
        {
            this.currentModel = BookmarkerModel.GetDefault();
            await this.currentModel.LoadAsync();

            this._shareOperation = args.ShareOperation;

            // ビュー モデルを使用して、共有されるコンテンツのメタデータを通信します
            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;

            this.addBookmarkView.Title = shareProperties.Title;
            this.addBookmarkView.Uri = (await this._shareOperation.Data.GetUriAsync()).ToString();

            Window.Current.Content = this;
            Window.Current.Activate();

            // 共有されるコンテンツの縮小版イメージをバックグラウンドで更新します
            if (shareProperties.Thumbnail != null)
            {
                var stream = await shareProperties.Thumbnail.OpenReadAsync();
                thumbnailImage.SetSource(stream);
                this.DefaultViewModel["ShowImage"] = true;
            }
        }
开发者ID:runceel,项目名称:winrtapps,代码行数:36,代码来源:ShareTargetPage.xaml.cs

示例15: BannerControl

        public BannerControl(GridView bannerCanv, XCollection<Banner> banners, Frame frame)
        {
            _frame = frame;         
            bannerCanv.Items?.Clear();
            var deviceWidth = Window.Current.CoreWindow.Bounds.Width;
            foreach (var banner in banners)
            {
                var bannerBitmap = new BitmapImage {UriSource = new Uri(banner.Image, UriKind.RelativeOrAbsolute)};

                var bannerImage = SystemInfoHelper.IsMobile() || deviceWidth < 800 ? new Image
                {
                    Source = bannerBitmap,
                    Stretch = Stretch.Fill,
                    MaxWidth = deviceWidth + 5
                } : new Image
                {
                    Source = bannerBitmap,
                    Stretch = Stretch.Fill,
                    MaxHeight = bannerCanv.MaxHeight                    
                };
                bannerImage.Tapped += OnBannerTap;                
                bannerImage.Tag = banner;
                bannerCanv.Visibility = Visibility.Visible;
                bannerImage.Visibility = Visibility.Visible;
                bannerCanv.Items?.Add(bannerImage);
            }
            if (SystemInfoHelper.IsMobile() || deviceWidth < 800)
                bannerCanv.MaxHeight = deviceWidth / 2.46;
        }
开发者ID:Korshunoved,项目名称:Win10reader,代码行数:29,代码来源:BannerControl.cs


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