We have the following popup in a WPF application that should display two images returned from the internet, but throws the toys out with 'The image is missing a frame' when it hits EndInit()
Never come across this error before and can't find any explanation online that relates to this use - could it be an issue with the downloaded image, and if so how do I check it?
Thank you
Public Sub PopupModals_ChequeImages(ImageOne() As Byte, ImageTwo() As Byte)
Try
MainPopUp = New Window
With MainPopUp
.Width = 800
.Height = 750
.ResizeMode = ResizeMode.NoResize
.Title = "Check Images"
.Icon = BitmapFrame.Create(ReturnIconImage("GIF_ICO.ico"))
End With
MainPopUpGrid = New Grid
NameScope.SetNameScope(MainPopUpGrid, New NameScope())
Dim vGrid As New Grid
For i As Integer = 0 To 2
Dim vRow As New RowDefinition
If i = 2 Then
vRow.Height = New GridLength(35)
Else
vRow.Height = New GridLength(35, GridUnitType.Star)
End If
MainPopUpGrid.RowDefinitions.Add(vRow)
Next
Dim UpperSV As New ScrollViewer
With UpperSV
.VerticalScrollBarVisibility = ScrollBarVisibility.Auto
End With
Grid.SetRow(UpperSV, 0)
MainPopUpGrid.Children.Add(UpperSV)
Dim LowerSV As New ScrollViewer
With LowerSV
.VerticalScrollBarVisibility = ScrollBarVisibility.Auto
End With
Grid.SetRow(LowerSV, 1)
MainPopUpGrid.Children.Add(LowerSV)
'Convert the files and load into the scrollviewers'
Dim vImage1 As New Image
Dim vBitmap As New BitmapImage
Using vStream As New IO.MemoryStream(ImageOne)
With vBitmap
.BeginInit()
.CreateOptions = BitmapCreateOptions.PreservePixelFormat
.CacheOption = BitmapCacheOption.OnLoad
.StreamSource = vStream
.EndInit()
.Freeze()
End With
vImage1.Source = vBitmap
End Using
UpperSV.Content = vImage1
Dim vImage2 As New Image
vBitmap = New BitmapImage
Using vStream As New IO.MemoryStream(ImageTwo)
With vBitmap
.BeginInit()
.CreateOptions = BitmapCreateOptions.PreservePixelFormat
.CacheOption = BitmapCacheOption.OnLoad
.StreamSource = vStream
.EndInit()
.Freeze()
End With
vImage2.Source = vBitmap
End Using
LowerSV.Content = vImage2
Dim DP As DockPanel = PopupStatusBar()
Grid.SetRow(DP, 2)
MainPopUpGrid.Children.Add(DP)
StatusBarLoaded("Check images...")
MainPopUp.Content = MainPopUpGrid
MainPopUp.WindowStartupLocation = WindowStartupLocation.CenterOwner
Dim CurApp As Application = Application.Current
Dim vWindow As Window = CurApp.MainWindow
MainPopUp.Owner = vWindow
MainPopUp.ShowDialog()
Catch ex As Exception
EmailError(ex)
End Try
End Sub
Full exception is
The image is missing a frame.
at System.Windows.Media.Imaging.BitmapDecoder.SetupDecoderFromUriOrStream(Uri uri, Stream stream, BitmapCacheOption cacheOption, Guid& clsId, Boolean& isOriginalWritable, Stream& uriStream, UnmanagedMemoryStream& unmanagedMemoryStream, SafeFileHandle& safeFilehandle)
at System.Windows.Media.Imaging.BitmapDecoder.CreateFromUriOrStream(Uri baseUri, Uri uri, Stream stream, BitmapCreateOptions createOptions, BitmapCacheOption cacheOption, RequestCachePolicy uriCachePolicy, Boolean insertInDecoderCache)
at System.Windows.Media.Imaging.BitmapImage.FinalizeCreation()
at System.Windows.Media.Imaging.BitmapImage.EndInit()
at HOAManagerClient051.PopupModals.PopupModals_ChequeImages(Byte[] ImageOne, Byte[] ImageTwo) in C:\Users\Dave\Documents\Visual Studio 2017\Projects\HOAManagerClient051\HOAManagerClient051\PopupModals.vb:line 3125
System.Runtime.InteropServices.COMException (0x88982F62): Exception from HRESULT: 0x88982F62
Images are returned like this
Await Task.Run(Sub()
Using response As HttpWebResponse = DirectCast(request.GetResponse(), HttpWebResponse)
Dim deserializer As New DataContractJsonSerializer(GetType(AllianceBank.CheckImageResponse))
checkResponseObject = DirectCast(deserializer.ReadObject(response.GetResponseStream()), AllianceBank.CheckImageResponse)
End Using
End Sub)
Dim frontImageRawGif As Byte() = Nothing
Dim backImageRawGif As Byte() = Nothing
Dim IsCheckImage As Boolean = True
Try
frontImageRawGif = Convert.FromBase64String(checkResponseObject.FrontImage)
Catch ex As Exception
IsCheckImage = False
End Try
Try
backImageRawGif = Convert.FromBase64String(checkResponseObject.BackImage)
Catch ex As Exception
IsCheckImage = False
End Try
User contributions licensed under CC BY-SA 3.0