Converting it to a byte array with code at bottom.
I then try to turn it into a bitmap file with this.
Dim arbyImage As Byte()
Dim msX As MemoryStream
Dim bmpOrig As Bitmap
Dim imgformatOrig As Imaging.ImageFormat
'Other code
arbyImage = Nothing : msX = Nothing : bmpOrig = Nothing : imgformatOrig = Nothing
bolOK = fnStringtoByteArray(strPht, arbyImage)
If bolOK Then
Try
msX = New MemoryStream(arbyImage)
Catch ex As Exception
clsEH.prAddError("fnSavePhotos - Failed to generate MemoryStream\n" & strSaveTo & strNewFile)
Exit Function
End Try
msX.Position = 0
Try
bmpOrig = New Bitmap(msX)'*********Fails Here
Catch ex As Exception
clsEH.prAddError("fnSavePhotos - Failed to make bmp from MemoryStream\n" & strSaveTo & strNewFile)
Exit Function
End Try
Try
imgformatOrig = bmpOrig.RawFormat
Catch ex As Exception
clsEH.prAddError("fnSavePhotos - Failed to get Original Format of bmpOrig\n" & strSaveTo & strNewFile)
Exit Function
End Try
Try
bmpOrig.Save(strSaveTo & strNewFile, imgformatOrig)
Catch ex As Exception
clsEH.prAddError("fnSavePhotos - Failed to save photo\n" & strSaveTo & strNewFile)
Exit Function
End Try
End If
The error I get is System.ArgumentException: Parameter is not valid. at System.Drawing.Bitmap..ctor(Stream stream)
I've made sure the memorystream is at the beginning - msX.Position = 0
I've tried using Image instead of bitmap
(error message changes to at System.Drawing.Image.FromStream(Stream stream, Boolean useEmbeddedColorManagement, Boolean validateImageData) - no other change)
'Either
Dim imgX As Image = Nothing
imgX = Image.FromStream(msX)
bmpOrig = New Bitmap(imgX)
'Or
Dim imgX As Image = Nothing
imgX = Image.FromStream(New MemoryStream(arbyImage))
bmpOrig = New Bitmap(imgX)
Private Function fnStringtoByteArray(ByVal strPhoto As String, ByRef arbyImage As Byte()) As Boolean
Dim arstrBytes() As String
Dim intByCnt As Byte
Dim strByte As String
fnStringtoByteArray = False
arstrBytes = Nothing : arbyImage = Nothing
Try
arstrBytes = strPhoto.Split(",")
Catch ex As Exception
Exit Function
End Try
intByCnt = 0
For Each strByte In arstrBytes
If IsNumeric(strByte) Then
If Val(strByte) >= 0 And Val(strByte) <= 255 Then
ReDim Preserve arbyImage(intByCnt)
arbyImage(intByCnt) = CByte(strByte)
intByCnt += 1
Else
Exit Function
End If
Else
Exit Function
End If
Next
fnStringtoByteArray = True
End Function

New Topic/Question
Reply




MultiQuote





|