简体   繁体   English

WP8空白图像被保存到库中

[英]WP8 Blank image being saved to Library

Im trying to save an image to the photo library in the phone. 我正在尝试将图像保存到手机的照片库中。 This is the XAML Mark up. 这是XAML标记。

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

I am trying to save the Canvas into an image. 我正在尝试将“画布”保存到图像中。 The textboxes are given values at runtime as well as the Image. 将在运行时为文本框以及图像提供值。 This is the code i have got to do this: 这是我要做的代码:

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

The code runs, but then it seems to generate an empty image. 该代码运行,但随后似乎会生成一个空图像。 Is there something i am missing? 有什么我想念的吗?

you forgot to bind your XAML with the actual bitmap. 您忘记了将XAML与实际位图绑定。

you can read more about Binding on MSDN 您可以阅读有关MSDN上绑定的更多信息

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

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