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


C# WriteableBitmap.ToImage方法代码示例

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


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

示例1: SaveImage

        public static void SaveImage(this UIElement uiElement)
        {
            var dialog = new SaveFileDialog
            {
                DefaultExt = ".png",
                Filter = "PNG | *.png | JPG | *.jpg",
            };
            var save = dialog.ShowDialog();
            if (save.HasValue && save.Value)
            {
                var saveStream = dialog.OpenFile();

                var bitmap = new WriteableBitmap(uiElement, new TranslateTransform());
                var image = bitmap.ToImage();
                if (dialog.SafeFileName.EndsWith(".png"))
                {
                    var encoder = new PngEncoder();
                    encoder.Encode(image, saveStream);
                }
                else if (dialog.SafeFileName.EndsWith(".jpg"))
                {
                    var encoder = new JpegEncoder();
                    encoder.Encode(image, saveStream);
                }

                saveStream.Close();
            }
        }
开发者ID:teshca,项目名称:android-geocaching,代码行数:28,代码来源:ImageHelper.cs

示例2: CreateTile

        public void CreateTile(WriteableBitmap tileImage, string tileName, Uri pageUri)
        {
            string tileImageFile = System.IO.Path.Combine(ApplicationSettingsManager.SHAREDSHELLCONTENT_PATH, tileName + ".png");

            using(IsolatedStorageFileStream ifs = ApplicationSettingsManager.UserStoreForApplication.OpenFile(tileImageFile, FileMode.Create, FileAccess.ReadWrite))
            {
                ExtendedImage image = tileImage.ToImage();
                image.WriteToStream(ifs, tileImageFile);
            }

            StandardTileData tileData = new StandardTileData
            {
                Title = String.Format("uknit - {0}", tileName),
                BackgroundImage = new Uri("isostore:/" + tileImageFile, UriKind.Absolute)
            };

            ShellTile.Create(pageUri, tileData);
        }
开发者ID:nshenoy,项目名称:uknit,代码行数:18,代码来源:ApplicationSettingsManager.cs

示例3: SaveCaptureImageToLocal

        public void SaveCaptureImageToLocal(FrameworkElement saveElement)
        {

            WriteableBitmap writeBitmap = new WriteableBitmap(saveElement,null); 
            string thirdDicUrl = "Shared/ShellContent/titles";
            using (var store = IsolatedStorageFile.GetUserStoreForApplication())
            {
                if (!store.DirectoryExists(thirdDicUrl))      
                    store.CreateDirectory(thirdDicUrl);

                using (var writer = new StreamWriter(new IsolatedStorageFileStream(SaveBackgroundImagePath, FileMode.Create, FileAccess.Write, store)))
                {
                    var pngEncoder = new ImageTools.IO.Png.PngEncoder();
                    pngEncoder.Encode(writeBitmap.ToImage(), writer.BaseStream);   
  
                    //MemoryStream controlStream = new MemoryStream();
                    //writeBitmap.SaveJpeg(controlStream,691,336, 0, 100);
                    //writeBitmap.SetSource(controlStream);
                    //writeBitmap.WritePNG(writer.BaseStream);
                }
            }
        }
开发者ID:rodmanwu,项目名称:dribbble-for-windows-phone-8,代码行数:22,代码来源:CustomLiveTitleHelper.cs

示例4: Button_Click

        private void Button_Click(object sender, RoutedEventArgs e)
        {
            this.Dispatcher.BeginInvoke(() =>
                {
                    FrameBorder.Visibility = Visibility.Collapsed;
                    ResultBorder.Visibility = Visibility.Visible;
                });

            Uri serviceUri = new Uri(Defines.BaseUri + "/services/account/uploadphoto");

            WebClient client = new WebClient();

            client.WriteStreamClosed += new WriteStreamClosedEventHandler((o, args) =>
            {
                loadingTextBlock.Visibility = Visibility.Collapsed;
                resultPanel.Visibility = Visibility.Visible;

                Defines.MainPage.RefreshUserInfo();
            });

            client.OpenWriteCompleted += new OpenWriteCompletedEventHandler((o, args) =>
            {
                WriteableBitmap bmp = new WriteableBitmap(frame.Source as BitmapSource);
                Stream encoded = bmp.ToImage().ToStreamByExtension("png");
                encoded.Seek(0, SeekOrigin.Begin);

                byte[] data = new byte[encoded.Length];
                encoded.Read(data, 0, (int)encoded.Length);
                args.Result.Write(data, 0, (int)data.Length);
                args.Result.Flush();
                args.Result.Close();
            });

            client.OpenWriteAsync(serviceUri, "POST");

            resultPhoto.Source = frame.Source;
        }
开发者ID:retran,项目名称:old-projects-backup,代码行数:37,代码来源:SettingsPhoto.xaml.cs

示例5: LoadCachedImageFromUrlAsync

        /// <summary>
        /// Loads an image asynchronously. If the image is already cached, it will be loaded from the cache. Otherwise it will be added to the cache
        /// </summary>
        /// <param name="url">An absolute URI pointing to the image</param>
        /// <returns>A Bitmap with the image</returns>
        public async static Task<ExtendedImage> LoadCachedImageFromUrlAsync(Uri url)
        {
            try
            {
                using (IsolatedStorageFile storage = IsolatedStorageFile.GetUserStoreForApplication())
                {
                    string file = Path.Combine(CacheFolder, getCachenameFromUri(url));

                    if (cacheContainsUri(url))
                    {
                        ExtendedImage cachedImage = new ExtendedImage();
                        using (IsolatedStorageFileStream cachedFile = storage.OpenFile(file, FileMode.Open, FileAccess.Read))
                        {
                            BitmapImage image = new BitmapImage();
                            image.SetSource(cachedFile);

                            WriteableBitmap tmp = new WriteableBitmap(image);
                            cachedImage = tmp.ToImage();

#if DEBUG
                            App.logger.log("Loaded image {0} from cached file {1}", url, file);
#endif
                            return cachedImage;
                        }
                    }
                    else
                    {
                        ExtendedImage loadedImage = await Helpers.LoadImageFromUrlAsync(url);

                        //GIF files don't support saving with imagetools
                        if (!url.ToString().EndsWith("gif", StringComparison.InvariantCultureIgnoreCase))
                            saveImageToCache(loadedImage, file, storage);

                        return loadedImage;
                    }
                }
            }
            catch (Exception e)
            {
                if (e is IOException)
                {
#if DEBUG
                    App.logger.log("Error loading from cache: {0}", url);
#endif
                }
#if DEBUG
                throw;
#endif
                return null;
            }
        }
开发者ID:TheInterframe,项目名称:SparklrWP-OLD,代码行数:56,代码来源:Image.cs

示例6: SaveTheImage

        private async Task SaveTheImage(WriteableBitmap bitmap)
        {
            if (await _storageService.FileExistsAsync(LockScreenFile))
            {
                await _storageService.DeleteFileAsync(LockScreenFile);
            }

            using (var fileStream = await _storageService.CreateFileAsync(LockScreenFile))
            {
                var encoder = new PngEncoder();
                var image = bitmap.ToImage();
                encoder.Encode(image, fileStream);
            }
        }
开发者ID:gep13,项目名称:Emby.WindowsPhone,代码行数:14,代码来源:LockScreenService.cs

示例7: UpdateTile

        public void UpdateTile(WriteableBitmap tileImage, string tileName)
        {
            ShellTile tile = ShellTile.ActiveTiles.FirstOrDefault(x => x.NavigationUri.ToString().Contains(tileName));

            if(tile != null)
            {
                string tileImageFile = System.IO.Path.Combine(ApplicationSettingsManager.SHAREDSHELLCONTENT_PATH, tileName + ".png");

                ApplicationSettingsManager.UserStoreForApplication.DeleteFile(tileImageFile);

                using(IsolatedStorageFileStream ifs = ApplicationSettingsManager.UserStoreForApplication.OpenFile(tileImageFile, FileMode.Create, FileAccess.ReadWrite))
                {
                    ExtendedImage image = tileImage.ToImage();
                    image.WriteToStream(ifs, tileImageFile);
                }

                StandardTileData tileData = new StandardTileData
                {
                    Title = String.Format("uknit - {0}", tileName),
                    BackgroundImage = new Uri("isostore:/" + tileImageFile, UriKind.Absolute)
                };

                tile.Update(tileData);
            }
        }
开发者ID:nshenoy,项目名称:uknit,代码行数:25,代码来源:ApplicationSettingsManager.cs


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