이미지를 Picturebox(VB6의 이미지)에서 문자열(Base64)로 변환하는 방법은 무엇입니까? (How to convert Image from a Picturebox(Image in VB6) to String(Base64)?)


문제 설명

이미지를 Picturebox(VB6의 이미지)에서 문자열(Base64)로 변환하는 방법은 무엇입니까? (How to convert Image from a Picturebox(Image in VB6) to String(Base64)?)

좋은 아침입니다.

Image3이라는 컨트롤이 있는 프로그램이 vb6에 있습니다. 이제 이 컨트롤이 이미지를 갖게 하려면 해당 이미지를 검색해야 합니다. 가급적이면 .jpg 파일은 내 SQL에 저장할 것이기 때문에 그렇게 할 필요가 없습니다. 왜냐하면 많은 이미지가 확실히 저장될 것이기 때문에 가까운 장래에 시스템이 느려질 것이기 때문입니다. (나를 위해) 가장 좋은 방법은 문자열로 변환하거나 그 반대로 변환하는 것입니다. 솔직히 저는 이 질문을 하고 싶지 않습니다. 검색 가능하고 그에 맞는 코드가 IO.MemoryStream이기 때문입니다. 제 문제는 참조에서 볼 수 없다는 것입니다. 이제 새 것을 다운로드하려고 하지만 VB6에서 이를 수락하지 않습니다.

누가 이 파일로 나를 밝혀줄 수 있습니까? 이미지를 문자열로 변환하는 다른 방법입니다.


참조 솔루션

방법 1:

Already done with the this question and to those want the same as I did here is the full code.

Private Sub Image3_DblClick()

CommonDialog1.InitDir = App.Path
CommonDialog1.FileName = ""
CommonDialog1.Filter = "Image files|*.jpg;"
CommonDialog1.DialogTitle = "All Picture Files"
CommonDialog1.ShowOpen

If CommonDialog1.FileName <> "" Then

        Dim arrImageByte() As Byte
        Dim bytBuf() As Byte
        Dim fNum As Integer
        Dim rs As New ADODB.Recordset
        Dim strPhotoPath As String
        Dim FileInputData As String
        Dim s As String

        Image3.Picture = LoadPicture(CommonDialog1.FileName)
        strPhotoPath = CommonDialog1.FileName

        ReDim arrImageByte(FileLen(strPhotoPath))
        fNum = FreeFile()
        Open strPhotoPath For Binary As #fNum
        Get #fNum, , arrImageByte
        Close fNum

        Open CommonDialog1.FileName For Binary As #1
        FileInputData = String(LOF(1), 0)
        Get #1, 1, FileInputData
        Close #1

        bytBuf = FileInputData

        s = CryptoBase64.Encode(bytBuf)

        Text8.Text = s

        Close

End If



‑‑‑‑‑‑‑‑‑‑‑‑‑‑‑‑‑‑‑‑‑‑‑‑‑‑Class Module‑‑‑‑‑‑‑‑‑‑‑‑‑‑‑‑‑‑‑‑‑‑‑‑‑‑‑‑‑‑

Option Explicit
Private Const CLASS_EXCEPT_BASE As Long = &H8004E300

Public Enum CryptoBase64ExceptEnum
  cbxGetOSVersFailed = CLASS_EXCEPT_BASE
  cbxNotNT
  cbxWinXPOrLaterReqd
  cbxWinVistaOrLaterReqd
  cbxStringToBinaryFailed
  cbxBinaryToStringFailed
End Enum

Public Enum Base64FormatEnum
  bfmtCrLF = 0
  bfmtLfOnly
  bfmtNone
End Enum

Public Enum OSVersionEnum
  osvWinXP = 501
  osvWinVista = 600
End Enum

Private Const VER_PLATFORM_WIN32_NT As Long = 2

Private Type OSVERSIONINFO
  dwOSVersionInfoSize As Long
  dwMajorVersion As Long
    ' Operating System     Value
    ' Windows 3.1            3
    ' Windows 95             4
    ' Windows 98             4
    ' Windows Me             4
    ' Windows NT 3.51        3
    ' Windows NT 4.0         4
    ' Windows 2000           5
    ' Windows XP             5
    ' Windows .Net Server    5
    ' Windows 2003 Server    5
    ' Windows 2003 R2 Server 5
    ' Windows Vista          6
    ' Windows 2008 Server    6
  dwMinorVersion As Long
    ' Operating System     Value
    ' Windows 3.1            1
    ' Windows 95             0
    ' Windows 98             10
    ' Windows Me             90
    ' Windows NT 3.51        51
    ' Windows NT 4.0         0
    ' Windows 2000           0
    ' Windows XP             1
    ' Windows .Net Server    1
    ' Windows 2003 Server    2
    ' Windows 2003 R2 Server 2
    ' Windows Vista          0
    ' Windows 2008 Server    0
    dwBuildNumber As Long
    dwPlatformId As Long
    szCSDVersion As String * 128

  'Extended information (optional), i.e. OSVERSIONINFOEX:
  wServicePackMajor As Integer
  wServicePackMinor As Integer
  wSuiteMask As Integer
  wProductType As Byte
    ' Operating System     Value
    ' NT Workstation         1
    ' NT Domain Controller   2
    ' NT Server              3
  wReserved As Byte
End Type

Private Declare Function GetVersionEx Lib "kernel32" Alias "GetVersionExA" (lpVersionInformation As OSVERSIONINFO) As Long

Private Const CRYPT_STRING_BASE64 As Long = 1
Private Const CRYPT_STRING_NOCR As Long = &H80000000
Private Const CRYPT_STRING_NOCRLF As Long = &H40000000

Private Declare Function CryptBinaryToString Lib "Crypt32" Alias "CryptBinaryToStringW" _
 (ByRef pbBinary As Byte, _
  ByVal cbBinary As Long, _
  ByVal dwFlags As Long, _
  ByVal pszString As Long, _
  ByRef pcchString As Long) As Long

Private Declare Function CryptStringToBinary Lib "Crypt32" Alias "CryptStringToBinaryW" _
 (ByVal pszString As Long, _
  ByVal cchString As Long, _
  ByVal dwFlags As Long, _
  ByVal pbBinary As Long, _
  ByRef pcbBinary As Long, _
  ByRef pdwSkip As Long, _
  ByRef pdwFlags As Long) As Long

Private m_OSVersion As OSVersionEnum
Private m_lngBase64Format As Long
Public Property Get Base64Format() As Base64FormatEnum
 If m_lngBase64Format = 0 Then
   Base64Format = bfmtCrLF
 ElseIf m_lngBase64Format = CRYPT_STRING_NOCR Then
   Base64Format = bfmtLfOnly
 Else
   Base64Format = bfmtNone
 End If
End Property
Public Property Let Base64Format(ByVal Format As Base64FormatEnum)
 If Format = bfmtLfOnly Then
   If m_OSVersion < osvWinXP Then
     Err.Raise cbxWinXPOrLaterReqd, "CryptoBase64.Base64Format", "This format is only supported in Windows XP/2003 and later"
   Else
     m_lngBase64Format = CRYPT_STRING_NOCR
   End If
 ElseIf Format = bfmtNone Then
   If m_OSVersion < osvWinVista Then
     Err.Raise cbxWinVistaOrLaterReqd, "CryptoBase64.Base64Format", "This format is only supported in Windows Vista/2008 and later"
   Else
     m_lngBase64Format = CRYPT_STRING_NOCRLF
   End If
 Else
   m_lngBase64Format = 0
 End If
End Property
Public Function Decode(ByRef Base64Buf As String) As Byte()
 Dim lngOutLen As Long
 Dim dwActualUsed As Long
 Dim bytBuf() As Byte

 ' Determine output buffer length required. Note:
 ' StrPtr(vbNullString) is just a way to get a null pointer,
 ' even though we're really talking about a Byte array here.
 CryptStringToBinary StrPtr(Base64Buf), _
                     Len(Base64Buf), _
                     CRYPT_STRING_BASE64, _
                     StrPtr(vbNullString), _
                     lngOutLen, _
                     0&, _
                     dwActualUsed

 ' Convert Base64 to binary.
 ReDim bytBuf(lngOutLen ‑ 1)

 If CryptStringToBinary(StrPtr(Base64Buf), _
                        Len(Base64Buf), _
                        CRYPT_STRING_BASE64, _
                        VarPtr(bytBuf(0)), _
                        lngOutLen, _
                        0&, _
                        dwActualUsed) = 0 Then
   Err.Raise cbxStringToBinaryFailed, "CryptoBase64.Decode", "CryptStringToBinary failed, error " & CStr(Err.LastDllError)
 Else
   Decode = bytBuf
 End If

 'Open App.Path & "\MyTestGif.gif" For Binary As #1
 'Put #1, 1, Decode
 'Close #1


End Function
Public Function Encode(ByRef BinaryBuf() As Byte) As String
 Dim bytBuf() As Byte
 Dim lngOutLen As Long
 Dim strBase64 As String

 'Determine Base64 output String length required.
 CryptBinaryToString BinaryBuf(0), _
                     UBound(BinaryBuf) + 1, _
                     CRYPT_STRING_BASE64 Or m_lngBase64Format, _
                     StrPtr(vbNullString), _
                     lngOutLen

 'Convert binary to Base64.
 Encode = String(lngOutLen, 0)

 If CryptBinaryToString(BinaryBuf(0), _
                        UBound(BinaryBuf) + 1, _
                        CRYPT_STRING_BASE64 Or m_lngBase64Format, _
                        StrPtr(Encode), _
                        lngOutLen) = 0 Then

   Err.Raise cbxBinaryToStringFailed, "CryptoBase64.Encode", "CryptBinaryToString failed, error " & CStr(Err.LastDllError)
    End If
End Function
Public Property Get OSVersion() As OSVersionEnum
 OSVersion = m_OSVersion
End Property
Private Sub Class_Initialize()
 Dim osvinfData As OSVERSIONINFO

 With osvinfData
   .dwOSVersionInfoSize = Len(osvinfData)
   .szCSDVersion = ""

   If GetVersionEx(osvinfData) = 0 Then
     Err.Raise cbxGetOSVersFailed, "CryptoBase64 Initialize", "GetVersionEx failed, error " & CStr(Err.LastDllError)
   End If

   If .dwPlatformId <> VER_PLATFORM_WIN32_NT Then
     Err.Raise cbxNotNT, "CryptoBase64 Initialize", "CryptoAPI is only available on NT‑based OSs"
   End If

   m_OSVersion = .dwMajorVersion * 100 + .dwMinorVersion
 End With

 Base64Format = bfmtCrLF
End Sub

Just add picbox,button and and a module for this to work

(by Shadow FiendShadow Fiend)

참조 문서

  1. How to convert Image from a Picturebox(Image in VB6) to String(Base64)? (CC BY‑SA 2.5/3.0/4.0)

#image #SQL #vb6






관련 질문

이미지가 추가될 때 div 높이가 과도하게 늘어남 (div height overstretching when image is appended)

MS-Outlook 임베디드 이미지를 가져오고 MS-Access VBA를 사용하여 파일 시스템에 저장 (Getting MS-Outlook embedded images and saving them within the file system using MS-Access VBA)

Android 이미지 갤러리 이미지 자르기 및 ImageView 설정 (Android Image Gallery Crop Image and set ImageView)

Facebook은 드래그하여 이미지를 닫는 데 어떤 라이브러리를 사용합니까? (What library does Facebook use for dismiss image by dragging?)

이미지를 Picturebox(VB6의 이미지)에서 문자열(Base64)로 변환하는 방법은 무엇입니까? (How to convert Image from a Picturebox(Image in VB6) to String(Base64)?)

HTML, Canvas 및 WebGL 간의 품질 차이 (Quality differences between HTML, Canvas and WebGL)

TBitmapImage는 Inno Setup 6에서 크기 조정된 디스플레이의 크기보다 크게 렌더링됩니다. (TBitmapImage is rendered larger than its size on scaled display in Inno Setup 6)

이미지 URL이 실제 이미지를 가리키는지 확인합니다. 문제를 일으키는 URL의 공백 (Check if an image URL points to an actual image. Space in URL in causing issue)

android studio에서 인텐트를 통해 여러 콘텐츠를 보내는 방법 (how can i send multiple contents through intent in android studio)

Squarespace 사이트용 CSS로 이미지의 위치를 완벽하게 제어 (Fully Control The Location of an Image with CSS for Squarespace site)

iText7을 사용하여 PDFButtonFormField에 이미지를 추가할 때 종횡비를 유지하는 방법 (How to Maintain Aspect Ratio when Adding an Image to a PDFButtonFormField using iText7)

png 이미지에서 픽셀 색상 추출 (extracting pixel color from png image)







코멘트