繁体   English   中英

Windows Phone 8.1在图像上写文本

[英]Windows Phone 8.1 write Text on an Image

所以我确实喜欢3小时的研究时间,却什么也没做。 我在运行时将持有BitmapImage作为属性的对象。 我想在此BitmapImage上写文本。 如何使用C#和XAML做到这一点?

我读到一些有关能够构造WriteableBitmap和.render()方法的信息,但是我只在Windows.UI.Xaml.Media.Imaging命名空间中找到了WriteableBitmap类。

谁能阻止我摘录?

我找到了一种使图像中的文本起作用的好方法。 我使用网格控件将一个Image和两个TextBox相互映射。 确保首先声明图像,这意味着首先渲染图像。

<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>

然后,我可以将整个Grid控件另存为“ Scresn Shot”,但宽度和高度只能与Grid实际的一样。

        RenderTargetBitmap renderTargetBitmap = new RenderTargetBitmap();
        await renderTargetBitmap.RenderAsync(Capture_Grid);
        var pixels = await renderTargetBitmap.GetPixelsAsync();
        Grid element = Capture_Grid;

//文件扩展名更正

        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();
        }

它还将图像(网格+ 2个文本框)保存在图像中心中。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM