|
[广告] VBA代码宝 - VBA编程加强工具 · VBA代码随查随用 · 内置多项VBA编程加强工具 ★ 免费下载 ★ ★ 使用手册★
Sub 按钮1_Click()
Cells.Clear
Dim fn, f
Dim arr() As Byte, H, i
fn = Application.GetOpenFilename("图像文件,*.*", , "请选文件", , MultiSelect:=True)
If Not IsArray(fn) Then Exit Sub
For Each f In fn
Open f For Binary As #1
H = LOF(1)
ReDim arr(1 To H)
Get #1, , arr
Close #1
'获取图片的像素高和宽。宽度不是4的倍数时需补零
PixelCol = 0: PixelRow = 0: Zeroize = 0
For i = 0 To 3
PixelCol = PixelCol + arr(i + 19) * 256 ^ i
Next
For i = 0 To 3
PixelRow = PixelRow + arr(i + 23) * 256 ^ i
Next
If PixelCol Mod 4 <> 0 Then Zeroize = PixelCol Mod 4
Dim brr()
ReDim brr(1 To PixelRow, 1 To PixelCol)
ascii_char = "$@B%8&WM#*oahkbdpqwmZO0QLCJUYXzcvunxrjft/\|()1{}[]?-_+~<>i!lI;:,\^`'. "
pLength = Len(ascii_char)
unit = (256# + 1) / pLength
CellRow = 0
For i = PixelRow To 1 Step -1
CellRow = CellRow + 1
CellCol = 0
For j = 1 To PixelCol * 3 Step 3
CellCol = CellCol + 1
lngPos = arr(11) + j + (i - 1) * (PixelCol * 3 + Zeroize)
bytTarget = arr(lngPos) * 0.299 + arr(lngPos + 1) * 0.587 + arr(lngPos + 2) * 0.114
brr(CellRow, CellCol) = Mid(ascii_char, Int(bytTarget / unit) + 1, 1)
Next
Next
[a1].Resize(PixelRow, PixelCol) = brr
Next
End Sub
24位图片.zip
(42.25 KB, 下载次数: 30)
|
|