本文整理汇总了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;
}
示例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;
//.........这里部分代码省略.........