简体   繁体   中英

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.

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

you can read more about Binding on MSDN

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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