Click here to Skip to main content
15,892,072 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Please help me to save a bitmapimage object to a folder...

What I have tried:

VB
Dim myImage as new System.windows.controls.image

myImage .Source=ObjBitmapImage

Dim bf As BitmapFrame = myImage.Source

Using fs as New FileStream(filePath, FileMode.Create)
       Dim enc As New JpegBitmapEncoder
       enc.Frames.Add(bf)
       enc.Save(fs)
End Using


But i am getting object cast error..
Posted
Updated 8-Sep-17 17:50pm
v2

1 solution

Here is a solution from a similar question that I answered last month:
VB
Private Sub SaveJpgImage(source As BitmapImage, photoLocation As String)

    SaveImage(source, photoLocation, New JpegBitmapEncoder())

End Sub

Private Sub SavePngImage(source As BitmapImage, photoLocation As String)

    SaveImage(source, photoLocation, New PngBitmapEncoder())

End Sub

Private Sub SaveImage(source As BitmapImage, photoLocation As String, encoder As BitmapEncoder)

    encoder.Frames.Add(BitmapFrame.Create(source))

    Using filestream = New FileStream(photoLocation, FileMode.Create)
        encoder.Save(filestream)
    End Using

End Sub

And to use:
VB
SaveJpgImage(myImage, ".\cropped.jpg")

Where myImage is of type BitmapImage.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900