이미지 (또는 wav 파일)를 추출하려고하는 웹 REST 서비스가 있습니다. 메모리 스트림을 통해 이미지 (jpg)를 가져 와서 그림 상자에 표시 한 다음 그림 상자를 파일에 저장할 수 있습니다. 그림 상자를 사용하고 메모리 스트림을 파일에 곧바로 저장하는 중간 단계를 없애고 싶습니다. 그러나 결과 파일은 jpg 파일로 보이지 않습니다. 열 때 손상된 파일 오류가 발생합니다.vb.net 파일로 웹 바이너리 저장
Dim msgURI As String
msgURI = "http://192.168.0.1/attachment/12345/0"
Dim Pic As New PictureBox()
Dim web_client As New WebClient()
web_client.Credentials = New NetworkCredential("XX", "XX")
Dim image_stream As New MemoryStream(web_client.DownloadData(msgURI))
Pic.Image = Image.FromStream(image_stream)
Dim bm As Bitmap = Pic.Image
Dim filename As String = "c:\temp\test.jpg"
bm.Save(filename, Imaging.ImageFormat.Jpeg)
을하고 잘 작동 다음과 같이
는내가 가지고있는 코드입니다.
Using file As New FileStream(filename, FileMode.Create, System.IO.FileAccess.Write)
Dim bytes As Byte() = New Byte(image_stream.Length - 1) {}
image_stream.Read(bytes, 0, CInt(image_stream.Length))
file.Write(bytes, 0, bytes.Length)
image_stream.Close()
End Using
내가 손상된 JPG 파일입니다 파일을 얻을 :
그러나 나는 비트 맵과의 PictureBox를 무시하려면 다음을 사용하는 경우.
도움을 주시면 감사하겠습니다.
테리