将WPF InkCanvas保存为JPG - 图像正在被裁剪 [英] saving WPF InkCanvas to a JPG - image is getting cropped

查看:141
本文介绍了将WPF InkCanvas保存为JPG - 图像正在被裁剪的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个WPF InkCanvas控件,用于在我的应用程序中捕获签名。控件看起来像这样 - 它是700x300

I have a WPF InkCanvas control I'm using to capture a signature in my application. The control looks like this - it's 700x300

替代文字http://img156.imageshack.us/img156/7885/inkcanvas.jpg

然而,当我将其保存为JPG时,生成的图像看起来像这样,也是700x300

However, when I save it as a JPG, the resulting image looks like this, also 700x300

替代文字http://img210.imageshack.us/img210/5668/saved.jpg

我正在使用的代码保存

            sigPath = System.IO.Path.GetTempFileName();

            MemoryStream ms = new MemoryStream();
            FileStream fs = new FileStream(sigPath, FileMode.Create);

            RenderTargetBitmap rtb = new RenderTargetBitmap((int)inkSig.Width, (int)inkSig.Height, 96d, 96d, PixelFormats.Default);
            rtb.Render(inkSig);
            JpegBitmapEncoder encoder = new JpegBitmapEncoder();
            encoder.Frames.Add(BitmapFrame.Create(rtb));

            encoder.Save(fs);
            fs.Close();

这是我正在使用的XAML:

This is the XAML I'm using:

<Window x:Class="Consent.Client.SigPanel"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    Background="Transparent" Topmost="True" AllowsTransparency="True"
Title="SigPanel" Left="0" Top="0" Height="1024" Width="768" WindowStyle ="None" ShowInTaskbar="False" ResizeMode="NoResize" WindowStartupLocation="CenterScreen" >

<Border BorderThickness="1" BorderBrush="Black" Background='#FFFFFFFF' x:Name='DocumentRoot' Width='750' Height='400' CornerRadius='10'>
    <StackPanel HorizontalAlignment="Center" VerticalAlignment="Center">
        <TextBlock Name="txtLabel" FontSize="24" HorizontalAlignment="Center" >Label</TextBlock>
        <InkCanvas Opacity="1" Background="Beige" Name="inkSig" Width="700" Height="300" />

        <StackPanel HorizontalAlignment="Center" Orientation="Horizontal">
            <Button FontSize="24" Margin="10" Width="150" Name="btnSave" Click="btnSave_Click">Save</Button>
            <Button FontSize="24" Margin="10" Width="150" Name="btnCancel" Click="btnCancel_Click">Cancel</Button>
            <Button FontSize="24" Margin="10" Width="150" Name="btnClear" Click="btnClear_Click">Clear</Button>
        </StackPanel>
    </StackPanel>
</Border>

过去这完美运作。我无法弄清楚在保存图像时导致图像移动的变化。

In the past this worked perfectly. I can't figure out what changed that is causing the image to shift when it is saved.

推荐答案

啊哈!问题是直接位于InkCanvas上方的TextBlock txtLabel 。当你删除黑线消失时。

Aha! The problem is the TextBlock txtLabel that is directly above the InkCanvas. When you remove that the black line disappears.

至于为什么会这样,我还不完全确定。

As for why that is happening, I'm not entirely sure yet.

这篇关于将WPF InkCanvas保存为JPG - 图像正在被裁剪的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆