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


C# WriteableBitmap.Render方法代碼示例

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


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

示例1: RunTest

 private async void RunTest()
 {
     await this.WaitForLoadedAsync();
     var wb = new WriteableBitmap(1, 1);
     await wb.Render(this.source);
     this.target.Source = wb;
 }
開發者ID:stavrianosy,項目名稱:BudgetManagementAssistant,代碼行數:7,代碼來源:WriteableBitmapRenderTestPage.xaml.cs

示例2: SaveButton_Click

        public async void SaveButton_Click(object sender, RoutedEventArgs e)
        {
            /* TO DO (and uncomment async above):
            if (_writeableBitmap != null)
            {
                var picker = new FileSavePicker {SuggestedStartLocation = PickerLocationId.PicturesLibrary};
                picker.FileTypeChoices.Add("Image", new List<string> { ".png" });
                picker.DefaultFileExtension = ".png";
                picker.SuggestedFileName = "photo";
                var savedFile = await picker.PickSaveFileAsync();

                try
                {
                    if (savedFile != null)
                    {
                        using (var output = await
                            savedFile.OpenAsync(FileAccessMode.ReadWrite))
                        {
                            var encoder =
                                await BitmapEncoder.CreateAsync(BitmapEncoder.PngEncoderId, output);

                            byte[] pixels;

                            using (var stream = _writeableBitmap.PixelBuffer.AsStream())
                            {
                                pixels = new byte[stream.Length];
                                await stream.ReadAsync(pixels, 0, pixels.Length);
                            }

                            encoder.SetPixelData(BitmapPixelFormat.Rgba8,
                                                    BitmapAlphaMode.Straight,
                                                    (uint)_writeableBitmap.PixelWidth,
                                                    (uint)_writeableBitmap.PixelHeight,
                                                    96.0, 96.0,
                                                    pixels);

                            await encoder.FlushAsync();
                            await output.FlushAsync();
                        }
                    }
                }
                catch (Exception ex)
                {
                    var s = ex.ToString();
                }
                finally
                {
                    CheckAndClearShareOperation();
                }
            } */
#if PROBLEM
            if(_writeableBitmap != null)
            {
                using (MemoryStream ms = new MemoryStream())
                {

                    // Convert image to byte[]
                    byte[] imgB = ConvertBitmapToByteArray(_writeableBitmap);
                    string base64image = Convert.ToBase64String(imgB);
                    App.CurrentPatient.ImageEncoded = base64image;
                }
                App.CurrentPatient.ImageName = App.CurrentPatient.FormatImageName();
            }
#endif
#if SECONDTRY
            if(_writeableBitmap != null)
            {
                //App.CurrentPatient.ImageBitmap.SetSource(_bitmap);
                MemoryStream ms = _writeableBitmap.PixelBuffer.AsStream().AsOutputStream();
                App.CurrentPatient.ImageBitmap.SetSource(s);
                App.CurrentPatient.ImageName = App.CurrentPatient.FormatImageName();
            }
#endif
            if (_writeableBitmap != null)
            {
                if(!String.IsNullOrEmpty(CaptionTextBox.Text))
                {   // Added Release 7.
                    // Adapted from https://social.msdn.microsoft.com/Forums/windowsapps/en-US/3af5874c-3d40-486e-a592-2b2044fb377b/problem-with-rendertargetbitmap-?forum=winappswithcsharp
                    var captionedBitmap = new  RenderTargetBitmap();
                    await captionedBitmap.RenderAsync(elementToRender);
                    //image.Source = bitmap;
                    ///IBuffer pixelBuffer = await bitmap.GetPixelsAsync();
                    ///byte[] pixels = pixelBuffer.ToArray();
                    var pixelBuffer = await captionedBitmap.GetPixelsAsync();
                    byte[] pixels = pixelBuffer.ToArray();
                    // Evidently we have to do the next 2 lines, even tho captioned bitmap is same size as uncaptioned:
                    _writeableBitmap = null;
                    _writeableBitmap = new WriteableBitmap((int)captionedBitmap.PixelWidth, (int)captionedBitmap.PixelHeight);
                    using (Stream stream = _writeableBitmap.PixelBuffer.AsStream())
                    {
                        await stream.WriteAsync(pixels, 0, pixels.Length);
                    }
#if FOR_REFERENCE
                    // If this was Win Phone, traditional way to do the same thing is something like...
                    // Adapted from http://bsubramanyamraju.blogspot.in/2014/03/windows-phone-imagemergings-merging.html 
                    TextBlock tb = new TextBlock();
                    tb.Text = CaptionTextBox.Text;
                    tb.TextWrapping = TextWrapping.Wrap;
                    tb.Foreground = new SolidColorBrush(Colors.Black);
                    tb.FontSize = 70;
//.........這裏部分代碼省略.........
開發者ID:TriagePic,項目名稱:TriagePic-WinStore,代碼行數:101,代碼來源:WebcamPage.xaml.cs


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