如何在VB.NET中将bitmapimage保存到文件夹中 [英] How can I save bitmapimage to a folder in VB.NET
本文介绍了如何在VB.NET中将bitmapimage保存到文件夹中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
请帮我把bitmapimage对象保存到文件夹中...
我尝试过:
Dim myImage as new System.windows.controls.image
myImage .Source = ObjBitmapImage
Dim bf As BitmapFrame = myImage.Source
使用 fs as 新 FileStream(filePath,FileMode.Create)
Dim enc As 新 JpegBitmapEncoder
enc.Frames。添加(bf)
enc.Save(fs)
结束 使用
但我收到了对象投射错误..
解决方案
以下是我上个月回答的类似问题的解决方案:
私有 Sub SaveJpgImage(source As BitmapImage,photoLocation 正如 字符串)
SaveImage(source,photoLocation,新 JpegBitmapEncoder())
结束 Sub
私有 Sub SavePngImage(source As BitmapImage, photoLocation 作为 字符串)
SaveImage(source,photoLocation,新 PngBitmapEncoder())
结束 Sub
私有 Sub SaveImage(source 作为 BitmapImage,photoLocation 作为 字符串,编码器 As BitmapEncoder)
encoder.Frames.Add(BitmapFrame.Create(source))
使用 filestream = 新 FileStream(photoLocation,FileMode.Create)
encoder.Save(filestream)
结束 使用
结束 Sub
使用:
SaveJpgImage(myImage, 。\ cropped.jpg)
其中myImage
的类型为BitmapImage
。
Please help me to save a bitmapimage object to a folder...
What I have tried:
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..解决方案Here is a solution from a similar question that I answered last month:
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:
SaveJpgImage(myImage, ".\cropped.jpg")
WheremyImage
is of typeBitmapImage
.
这篇关于如何在VB.NET中将bitmapimage保存到文件夹中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文