Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/267.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# BitmapSource到Windows Phone的流中_C#_Windows Phone 7 - Fatal编程技术网

C# BitmapSource到Windows Phone的流中

C# BitmapSource到Windows Phone的流中,c#,windows-phone-7,C#,Windows Phone 7,我有一个类,它需要一个流来旋转手机摄像头的图像。我遇到的问题是,当从独立存储加载图片时(即在用户先前保存图片之后),它会加载到位图源中 如果可能,我想将位图源“提取”回流中?有人知道它是否在WP7中使用silverlight吗 谢谢您不必直接将其拉回到位图源中,但您可以通过IsolatedStorageFileStream类到达那里 下面是我的类版本,其方法接受流(您的代码显然比我的代码做得更多,但这对于我们的目的来说应该足够了) 然后使用我们从独立存储中提取的文件中的数据调用该类: priva

我有一个类,它需要一个流来旋转手机摄像头的图像。我遇到的问题是,当从独立存储加载图片时(即在用户先前保存图片之后),它会加载到位图源中

如果可能,我想将位图源“提取”回流中?有人知道它是否在WP7中使用silverlight吗


谢谢

您不必直接将其拉回到位图源中,但您可以通过
IsolatedStorageFileStream
类到达那里

下面是我的类版本,其方法接受流(您的代码显然比我的代码做得更多,但这对于我们的目的来说应该足够了)

然后使用我们从独立存储中提取的文件中的数据调用该类:

private void LoadFromIsostore_Click(object sender, RoutedEventArgs e)
{
    using (IsolatedStorageFile file = IsolatedStorageFile.GetUserStoreForApplication())
    {
        using (IsolatedStorageFileStream fs = file.OpenFile("saved.image", FileMode.Open))
        {
            MyPhotoClass c = new MyPhotoClass();
            BitmapSource picture = c.ConvertToBitmapSource(fs);
            MyPicture.Source = picture;
        }
    }
}
注意,我们使用的是直接从
OpenFile
方法返回的
IsolatedStorageFileStream
对象。这是一个流,这正是ConvertToBitmapSource所期望的

如果这不是您想要的,或者如果我误解了您的问题,请告诉我…

尝试一下:

WriteableBitmap bmp = new WriteableBitmap((BitmapSource)img);

using (MemoryStream stream = new MemoryStream()) {

    bmp.SaveJpeg(stream, bmp.PixelWidth, bmp.PixelHeight, 0, 100);
    return stream;
}
对我来说这不管用!用户没有SaveJpeg方法。
WriteableBitmap bmp = new WriteableBitmap((BitmapSource)img);

using (MemoryStream stream = new MemoryStream()) {

    bmp.SaveJpeg(stream, bmp.PixelWidth, bmp.PixelHeight, 0, 100);
    return stream;
}
        var background = Brushes.Transparent;

        var bmp = Viewport3DHelper.RenderBitmap(viewport, 500, 500, background);

        BitmapEncoder encoder;
        string ext = Path.GetExtension(FileName);
        switch (ext.ToLower())
        {

            case ".png":
                var png = new PngBitmapEncoder();
                png.Frames.Add(BitmapFrame.Create(bmp));
                encoder = png;
                break;
            default:
                throw new InvalidOperationException("Not supported file format.");
        }

        //using (Stream stm = File.Create(FileName))
        //{
        //    encoder.Save(stm);
        //}

        using (MemoryStream stream = new MemoryStream())
        {
            encoder.Save(stream);

            this.pictureBox1.Image = System.Drawing.Image.FromStream(stream);
        }