[英]Windows Phone 8.1 write Text on an Image
so I did like 3 h hours of research and could not get anything working yet. 所以我确实喜欢3小时的研究时间,却什么也没做。 I got objects holding a BitmapImage as a property at runtime. 我在运行时将持有BitmapImage作为属性的对象。 I want to write text on this BitmapImage. 我想在此BitmapImage上写文本。 How am I able to do so using C# & XAML? 如何使用C#和XAML做到这一点?
I read something about being able to construct a WriteableBitmap and a .render()-method, but I only found a WriteableBitmap Class in the Windows.UI.Xaml.Media.Imaging Namespace. 我读到一些有关能够构造WriteableBitmap和.render()方法的信息,但是我只在Windows.UI.Xaml.Media.Imaging命名空间中找到了WriteableBitmap类。
Can anyone prevent me a snippet to start from? 谁能阻止我摘录?
I found a nice way to get text in images to work. 我找到了一种使图像中的文本起作用的好方法。 I use a Grid Control to map an Image and two TextBox into onto each other. 我使用网格控件将一个Image和两个TextBox相互映射。 Make sure the Image is stated first, which means it is rendered first. 确保首先声明图像,这意味着首先渲染图像。
<Grid Grid.Row="1" x:Name="Capture_Grid">
<Image Binding="{Binding Image}" />
<TextBox x:Name="UpperCaptionBorder_TextBox" Style="{StaticResource CaptionTextBoxStyle}"
Text="text" TextWrapping="Wrap" FontSize="32"
HorizontalAlignment="Center" VerticalAlignment="Bottom"
SelectionChanged="UpperCaption_TextBox_SelectionChanged"
/>
<TextBox x:Name="LowerCaptionBorder_TextBox" Style="{StaticResource CaptionTextBoxStyle}"
Text="text" TextWrapping="Wrap" FontSize="32"
HorizontalAlignment="Center" VerticalAlignment="Bottom"
SelectionChanged="LowerCaption_TextBox_SelectionChanged"
/>
</Grid>
Then I can save the whole Grid control as a 'Scresn Shot', but it will only be as width and height as the Grid actually is. 然后,我可以将整个Grid控件另存为“ Scresn Shot”,但宽度和高度只能与Grid实际的一样。
RenderTargetBitmap renderTargetBitmap = new RenderTargetBitmap();
await renderTargetBitmap.RenderAsync(Capture_Grid);
var pixels = await renderTargetBitmap.GetPixelsAsync();
Grid element = Capture_Grid;
// file extension correction //文件扩展名更正
var file = await KnownFolders.PicturesLibrary.CreateFileAsync("pic.png", CreationCollisionOption.ReplaceExisting);
using (IRandomAccessStream stream = await file.OpenAsync(FileAccessMode.ReadWrite))
{
var encoder = await
BitmapEncoder.CreateAsync(BitmapEncoder.JpegEncoderId, stream);
byte[] bytes = pixels.ToArray();
encoder.SetPixelData(BitmapPixelFormat.Bgra8,
BitmapAlphaMode.Ignore,
(uint)renderTargetBitmap.PixelWidth,
(uint)renderTargetBitmap.PixelHeight,
96, 96, bytes);
await encoder.FlushAsync();
}
It also saves the Image (Grid + 2 TextBoxes) right in the Image Hub. 它还将图像(网格+ 2个文本框)保存在图像中心中。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.