오케이 그래서 공개적으로 내 더러운 코드를 방송하기 위해 여기에 무슨 일이 생겼는지.
참고 : 이것은 한 번 사용 된 다음 버려 지도록 설계된 해킹입니다.
이 메서드는 액세스 테이블에서 1 행의 데이터가 포함 된 datarowview를 가져옵니다. 이미지는 OLE 직렬화로 래핑됩니다. Microsoft는이 방식의 작동 방식에 완전히 익숙하지 않지만 Microsoft 응용 프로그램을 사용하여 개체를 다른 어떤 것에 임베드하는 방법을 알고 있습니다. (예 : 이미지를 Excel 셀로). 필자는 전체 필드를 Byte 배열로로드하고 필드 내에서 이미지 데이터의 시작을 나타내는 3 개의 동시 항목 (FF D8 FF)을 검색하기 위해 이미지 주변의 직렬화 정크를 제거해야했습니다.
Private Function GetImageFromRow(ByRef row As DataRowView, ByVal columnName As String) As Bitmap
Dim oImage As Bitmap = New Bitmap("c:\default.jpg")
Try
If Not IsDBNull(row(columnName)) Then
If row(columnName) IsNot Nothing Then
Dim mStream As New System.IO.MemoryStream(CType(row(columnName), Byte()))
If mStream.Length > 0 Then
Dim b(Convert.ToInt32(mStream.Length - 1)) As Byte
mStream.Read(b, 0, Convert.ToInt32(mStream.Length - 1))
Dim position As Integer = 0
For index As Integer = 0 To b.Length - 3
If b(index) = &HFF And b(index + 1) = &HD8 And b(index + 2) = &HFF Then
position = index
Exit For
End If
Next
If position > 0 Then
Dim jpgStream As New System.IO.MemoryStream(b, position, b.Length - position)
oImage = New Bitmap(jpgStream)
End If
End If
End If
End If
Catch ex As Exception
Throw New ApplicationException(ex.Message, ex)
End Try
Return oImage
End Function
그러면이 데이터를 비트 맵으로 끌어 내야합니다. 따라서 액세스 테이블의 각 행에 대해 비트 맵을 추출한 다음 해당 MySQL 항목을 업데이트하십시오.
괜찮 았지만 아마 더 나은 방법으로 직렬화를 제거했을 수도 있습니다.