This project is read-only.

Export to JPG throws UnsupportedImageFormatException

Aug 23, 2010 at 11:46 PM

I am trying to export a Map control to a JPG.

The Map derives from the Silverlight MultiScaleImage control. There was a problem writing out the control directly because I get the Pixel Access Security Exception. It seems like this workflow might gets around it.

The following code runs fine, and a file gets created, but it's empty. I also get the UnsupportedImageFormatException after the code has run (I can't tell where it's being generated from). What am I doing wrong?

        Dim sfd As SaveFileDialog = New SaveFileDialog()
        sfd.Filter = "Image Files (*.jpg)|*.jpg "
        If Not sfd.ShowDialog() Then
        End If

        Dim wb As WriteableBitmap = New WriteableBitmap(Map, Nothing)
        ImageTools.IO.Encoders.AddEncoder(Of JpegEncoder)()

        Dim mStream As MemoryStream = New MemoryStream()
        Dim write As StreamWriter = New StreamWriter(mStream)

        Dim myImage As Image = New Image()

            Using stream As Stream = sfd.OpenFile()
                Dim encoder As JpegEncoder = New JpegEncoder()
                encoder.Encode(myImage, stream)
            End Using
        Catch ex As Exception
        End Try