WP8空白图像保存到库中

时间:2013-12-28 17:40:33

标签: c# visual-studio-2012 windows-phone-8 imaging

我试图将图像保存到手机中的照片库中。这是XAML Mark up。

<Canvas x:Name="canMeme" HorizontalAlignment="Left" Height="400" Margin="26,134,0,0" VerticalAlignment="Top" Width="400">
    <Image x:Name="imgMeme" Height="400" Width="400"/>
    <TextBlock x:Name="topText" Width="400" TextWrapping="Wrap" HorizontalAlignment="Center" FontWeight="Bold" TextAlignment="Center" Text="Am i the only one around here" FontSize="40" Foreground="White"/>
    <TextBlock x:Name="bottomText" TextWrapping="Wrap" Text="TextBlock" Canvas.Top="372" Width="400" HorizontalAlignment="Center" TextAlignment="Center" FontWeight="Bold" Height="28" Margin="0,0,0,20" />
</Canvas>

我正在尝试将Canvas保存到图像中。文本框在运行时和Image中都给出了值。这是我必须做的代码:

try
{

    using (MemoryStream ms = new MemoryStream())
    {
        Extensions.SaveJpeg(imagebitmap, ms, imagebitmap.PixelWidth, imagebitmap.PixelHeight,0,100);
        ms.Seek(0, SeekOrigin.Begin);
        library.SavePicture(string.Format("Images\\{0}.jpg", name.ToString()), ms);
    }
    MessageBox.Show(string.Format("Image has been saved as {0}", name.ToString()));
}
catch (Exception ex)
{
    MessageBox.Show(ex.ToString());
}

代码运行,但它似乎生成一个空图像。有什么我想念的吗?

1 个答案:

答案 0 :(得分:0)

您忘记将XAML与实际位图绑定。

您可以阅读有关MSDN上绑定的更多信息