2 Replies - 8232 Views - Last Post: 06 August 2012 - 06:15 AM Rate Topic: -----

#1 complete  Icon User is offline

  • D.I.C Head

Reputation: 0
  • View blog
  • Posts: 109
  • Joined: 12-April 07

How Do I load a BitmapImage in WPF?

Posted 03 August 2012 - 08:41 AM

In a silverlight app, I have a BitmapImage defined as System.Windows.Media.Imaging.BitmapImage and it as a method called "SetSource" where I can set the source like this:
	BitmapImage bitmap = new BitmapImage(); 
	System.IO.Stream stream = _scene.GetStream(); 
	if (stream == null) return; 

In a WPF application I have also have a Bitmap image defined as System.Windows.Media.Imaging.BitmapImage but there is no SetSource method. How do I set the source in a WPF app like I do in a Silverlight app?

Also, it is a stream, not a string. It is not a URI. so "UriSource" method does not work. I tried this:
        System.IO.Stream stream = _scene.GetStream(); 
        if (stream == null) return; 
        BitmapImage bitmap = new BitmapImage(); 
        bitmap.UriSource = new Uri(stream.ToString()); 

And at runtime, it threw an error tha URI cannot be determined. Is the URI an identifier for the intranet? Are you sure that this is not a silverlight thing? I am doing a WPF application

Is This A Good Question/Topic? 0
  • +

Replies To: How Do I load a BitmapImage in WPF?

#2 Curtis Rutland  Icon User is offline

  • (╯□)╯︵ (~ .o.)~
  • member icon

Reputation: 5103
  • View blog
  • Posts: 9,283
  • Joined: 08-June 10

Re: How Do I load a BitmapImage in WPF?

Posted 03 August 2012 - 09:09 AM


First, the C# Advanced Discussion forum is for discussion topics only. Help questions go in the C# forum. However, since this question is specifically about WPF, I've moved it to the WPF forum.

This link might help:

Was This Post Helpful? 0
  • +
  • -

#3 bflosabre91  Icon User is offline

  • D.I.C Lover

Reputation: 105
  • View blog
  • Posts: 1,439
  • Joined: 22-February 08

Re: How Do I load a BitmapImage in WPF?

Posted 06 August 2012 - 06:15 AM

Not sure if this will help or not but here is what i use to get an image from a memorystream. Its in vb but I'm sure its not much different. the variable "data" is a byte array that is grabbed from a database.

          data = CType(cmd.ExecuteScalar(), Byte())
        Dim strm As New MemoryStream
        Dim bi As New BitmapImage
        If data IsNot Nothing Then
            strm.Write(data, 0, data.Length)
            strm.Position = 0
            Dim img As System.Drawing.Image = System.Drawing.Image.FromStream(strm)

            Dim ms As New MemoryStream
            img.Save(ms, System.Drawing.Imaging.ImageFormat.Bmp)
            ms.Seek(0, SeekOrigin.Begin)
            bi.StreamSource = ms
        End If

This post has been edited by bflosabre91: 06 August 2012 - 06:16 AM

Was This Post Helpful? 0
  • +
  • -

Page 1 of 1