• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

C# Imaging.BitmapImage类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

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



BitmapImage类属于Windows.UI.Xaml.Media.Imaging命名空间,在下文中一共展示了BitmapImage类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的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


示例16: BlankPage_CommandsRequested

        private void BlankPage_CommandsRequested(SettingsPane sender, SettingsPaneCommandsRequestedEventArgs args)
        {
            SettingsCommand cmd = new SettingsCommand("sample", "Sample Custom Setting", (x) =>
            {
                SettingsFlyout settings = new SettingsFlyout();
                settings.FlyoutWidth = (Callisto.Controls.SettingsFlyout.SettingsFlyoutWidth)Enum.Parse(typeof(Callisto.Controls.SettingsFlyout.SettingsFlyoutWidth), settingswidth.SelectionBoxItem.ToString());
                //settings.HeaderBrush = new SolidColorBrush(Colors.Orange);
                //settings.Background = new SolidColorBrush(Colors.White);
                settings.HeaderText = "Foo Bar Custom Settings";

                BitmapImage bmp = new BitmapImage(new Uri("ms-appx:///Assets/SmallLogo.png"));

                settings.SmallLogoImageSource = bmp;

                StackPanel sp = new StackPanel();

                ToggleSwitch ts = new ToggleSwitch();
                ts.Header = "Download updates automatically";

                Button b = new Button();
                b.Content = "Test";

                sp.Children.Add(ts);
                sp.Children.Add(b);

                settings.Content = sp;

                settings.IsOpen = true;

                ObjectTracker.Track(settings);
            });

            args.Request.ApplicationCommands.Add(cmd);
        }
开发者ID:fransstridh,项目名称:callisto,代码行数:34,代码来源:SettingsSample.xaml.cs


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


示例18: GetImageAsync

 public async static Task<BitmapImage> GetImageAsync(StorageFile storageFile)
 {
     BitmapImage bitmapImage = new BitmapImage();
     FileRandomAccessStream stream = (FileRandomAccessStream)await storageFile.OpenAsync(FileAccessMode.Read);
     bitmapImage.SetSource(stream);
     return bitmapImage;
 }
开发者ID:Ivalaostia,项目名称:UniversalHelpers,代码行数:7,代码来源:Utilities.cs


示例19: Convert

        public object Convert(object value, Type targetType, object parameter, string language)
        {
            int size;
            int.TryParse(parameter as string, out size);

            var url = value as string;
            Uri uri;
            if (url == null)
                uri = value as Uri;
            else
                uri = new Uri(url);

            if (uri == null)
                return null;

            var bitmap = new BitmapImage(uri);

            if (size != 0)
            {
                bitmap.DecodePixelHeight = size;
                bitmap.DecodePixelWidth = size;
            }

            return bitmap;
        }
开发者ID:haroldma,项目名称:Audiotica,代码行数:25,代码来源:ImageSourceConverter.cs


示例20: MainPage

        public MainPage()
        {
            this.InitializeComponent();

            // create Flickr feed reader for unicorn images
            var reader = new FlickrReader("unicorn");

            TimeSpan period = TimeSpan.FromSeconds(5);
            // display neew images every five seconds
            ThreadPoolTimer PeriodicTimer = ThreadPoolTimer.CreatePeriodicTimer(
                async (source) =>
                {
                    // get next image
                    var image = await reader.GetImage();

                    if (image != null)
                    {
                        // we have to update UI in UI thread only
                        await CoreApplication.MainView.CoreWindow.Dispatcher.RunAsync(CoreDispatcherPriority.Normal,
                        () =>
                        {
                            // create and load bitmap
                            BitmapImage bitmap = new BitmapImage();
                            bitmap.UriSource = new Uri(image, UriKind.Absolute);
                            // display image
                            splashImage.Source = bitmap;
                        }
                        );
                    }
                }, period);
        }
开发者ID:starnovsky,项目名称:IoTDisplay,代码行数:31,代码来源:MainPage.xaml.cs



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
C# Imaging.WriteableBitmap类代码示例发布时间:2022-05-26
下一篇:
C# Animation.Storyboard类代码示例发布时间:2022-05-26
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap