Thursday, 2 October 2014

Cara merubah hexadecimal to image pada vb6

berikut adalah codingan dari cara merubah atau konversi dari hexadecimal ke image atau gambar pada vb6

Private Sub cmdHexToImage_Click()
 Dim s As String
 Dim b() As Byte

 Open App.Path & "\t-rex_hex.txt" For Binary As #2

 s = String(LOF(2), 0)

 Get #2, 1, s

 Close #2

 b = Hex2ByteArr(s)

 Open App.Path & "\new_image.jpg" For Binary As #3
 Put #3, 1, b
 Close #3
End Sub


Public Function Hex2ByteArr(sHex As String) As Byte()
 '
 ' Call this function and write the byte array it returns back to disk
 '
 Dim bArr() As Byte
 Dim nUBound As Long, n As Long
   
 'Remove all spaces in the hex string
 sHex = Replace(sHex, " ", "")
   
 'Since each byte takes up 2 hex numbers the string length must be dividable by 2
 If Not Len(sHex) Mod 2 = 0 Then
   'you should throw an error here
   Exit Function
 End If
   
 nUBound = Len(sHex) \ 2 - 1
   
 ReDim bArr(nUBound)
   
 For n = 0 To nUBound
   k = CInt("&H" & Mid$(sHex, n * 2 + 1, 2))
   bArr(n) = k 'CInt("&H" & Mid$(sHex, n * 2 + 1, 2))
 Next

 Hex2ByteArr = bArr
End Function

download project nya di sini :
http://www.4shared.com/rar/Bqx9p-7xce/imagetostring.html
Perhatian: Yuk Baca Artikel bagus di Nurul Musthofa

Artikel Terkait

No comments:

Post a Comment

 

Network

Pesan

Semoga situs ini bermanfaat