English 中文(简体)
为什么把图像的来源推向不发挥作用?
原标题:Why is streaming source of an image not working?

我正在使用以下法规,将图像来源纳入主流:

        BitmapImage Art3 = new BitmapImage();
        using (FileStream stream = File.OpenRead("c:\temp\Album.jpg"))
        {
            Art3.BeginInit();
            Art3.StreamSource = stream;
            Art3.EndInit();
        }
        artwork.Source = Art3;

“艺术作品”是XAML的物体,其图像应显示在其中。 该法典不应打上形象,而是锁定它,而没有显示它,而缺省的形象则成为“无”。 我的猜测是,我没有适当利用这一流,我的形象已经消失。 帮助?

最新资料:

我现在使用朋友向我建议的以下法典:

        BitmapImage Art3 = new BitmapImage();

        FileStream f = File.OpenRead("c:\temp\Album.jpg");

        MemoryStream ms = new MemoryStream();
        f.CopyTo(ms);
        f.Close();

        Art3.BeginInit();
        Art3.StreamSource = ms;
        Art3.EndInit();   

        artwork.Source = Art3;

由于某些奇怪的原因,该法典有以下错误:

图像无法编码。 形象头盔可能腐败。

我做了什么错误? 我相信,我试图装满的图像并非腐败。

问题回答

我利用以下法典解决这一问题:

        BitmapImage Art3 = new BitmapImage();

        FileStream f = File.OpenRead("c:\temp\Album.jpg");

        MemoryStream ms = new MemoryStream();
        f.CopyTo(ms);
        ms.Seek(0, SeekOrigin.Begin);
        f.Close();

        Art3.BeginInit();
        Art3.StreamSource = ms;
        Art3.EndInit();   

        artwork.Source = Art3; 

感谢大家努力帮助我!

处置源流将造成比特图米格不再显示上游的任何情况。 当你不再使用比特图时,你必须跟踪并处置。

这也许会简化。

BitmapImage Art3 = new BitmapImage(new Uri("file:///c:/temp/Album.jpg"));

您:

        BitmapImage Art3 = new BitmapImage();
        using (FileStream stream = File.OpenRead("c:\temp\Album.jpg"))
        {
            Art3.BeginInit();
            Art3.StreamSource = stream;
            stream.Flush();
            Art3.EndInit();
        }
        artwork.Source = Art3;




相关问题
Anyone feel like passing it forward?

I m the only developer in my company, and am getting along well as an autodidact, but I know I m missing out on the education one gets from working with and having code reviewed by more senior devs. ...

NSArray s, Primitive types and Boxing Oh My!

I m pretty new to the Objective-C world and I have a long history with .net/C# so naturally I m inclined to use my C# wits. Now here s the question: I feel really inclined to create some type of ...

C# Marshal / Pinvoke CBitmap?

I cannot figure out how to marshal a C++ CBitmap to a C# Bitmap or Image class. My import looks like this: [DllImport(@"test.dll", CharSet = CharSet.Unicode)] public static extern IntPtr ...

How to Use Ghostscript DLL to convert PDF to PDF/A

How to user GhostScript DLL to convert PDF to PDF/A. I know I kind of have to call the exported function of gsdll32.dll whose name is gsapi_init_with_args, but how do i pass the right arguments? BTW, ...

Linqy no matchy

Maybe it s something I m doing wrong. I m just learning Linq because I m bored. And so far so good. I made a little program and it basically just outputs all matches (foreach) into a label control. ...

热门标签