Windows phone 7 将usercontrol呈现给MediaLibrary中的图像

Windows phone 7 将usercontrol呈现给MediaLibrary中的图像,windows-phone-7,Windows Phone 7,这应该将MyUIElement的渲染保存为bmp,然后将其保存为medialibrary中的Jpeg格式,但我在使用library.SavePicture(“证书”,流)的行中得到的值不在预期范围内错误 有什么想法吗?我犯了和你一样的错误。我按照上面的例子解决了这个问题 因此,您的方法应该如下所示 private void SaveAsPicture_Click(object sender, RoutedEventArgs e) { WriteableBitmap bmp = new W

这应该将MyUIElement的渲染保存为bmp,然后将其保存为medialibrary中的Jpeg格式,但我在使用
library.SavePicture(“证书”,流)的行中得到的
值不在预期范围内
错误


有什么想法吗?

我犯了和你一样的错误。我按照上面的例子解决了这个问题

因此,您的方法应该如下所示

private void SaveAsPicture_Click(object sender, RoutedEventArgs e)
{
    WriteableBitmap bmp = new WriteableBitmap(MyUIElement, null);
    var library = new MediaLibrary();
    MemoryStream stream = new MemoryStream();
    bmp.SaveJpeg(stream, 100, 100, 0, 90);
    library.SavePicture("Certificate", stream);
}

看到了吗?但它会显示在手机的照片库中吗?这个问题/答案显示了如何保存到隔离存储,我认为这可能是相关的。代码中的哪一行导致错误?library.SavePicture(“Certificate”,stream);
private void SaveAsPicture_Click(object sender, RoutedEventArgs e)
{
    WriteableBitmap bmp = new WriteableBitmap(MyUIElement, null);
    library.SavePicture("Certificate", stream);
    String tempJPEG = "TempJPEG";

    // Create a virtual store and file stream. Check for duplicate tempJPEG files.
    var myStore = IsolatedStorageFile.GetUserStoreForApplication();
    if (myStore.FileExists(tempJPEG))
    {
        myStore.DeleteFile(tempJPEG);
    }

    IsolatedStorageFileStream myFileStream = myStore.CreateFile(tempJPEG);

    bmp.SaveJpeg(myFileStream, wb.PixelWidth, wb.PixelHeight, 0, 85);
    myFileStream.Close();

    // Create a new stream from isolated storage, and save the JPEG file to the media library on Windows Phone.
    myFileStream = myStore.OpenFile(tempJPEG, FileMode.Open, FileAccess.Read);

    // Save the image to the camera roll or saved pictures album.
    MediaLibrary library = new MediaLibrary();

        // Save the image to the camera roll album.
    library.SavePicture("Certificate", myFileStream);
}