#2
冬瓜汤2023-12-22 12:09
回复 楼主 yuma
|
' 图片宽度和高度
imgWidth = 100
imgHeight = 200
' 计算图像数据的大小
imgDataSize = imgWidth * imgHeight * 3
' 创建 BMP 文件头
bmpHeader = Chr(66) & Chr(77) & _
Chr(imgDataSize And 255) & _
Chr((imgDataSize \ 256) And 255) & _
Chr(((imgDataSize \ 256) \ 256) And 255) & _
Chr((((imgDataSize \ 256) \ 256) \ 256) And 255) & _
Chr(0) & Chr(0) & Chr(0) & Chr(0) & _
Chr(54) & Chr(0) & Chr(0) & Chr(0) & _
Chr(40) & Chr(0) & Chr(0) & Chr(0) & _
Chr(imgWidth And 255) & Chr((imgWidth \ 256) And 255) & _
Chr(0) & Chr(0) & _
Chr(imgHeight And 255) & Chr((imgHeight \ 256) And 255) & _
Chr(0) & Chr(0) & _
Chr(1) & Chr(0) & _
Chr(24) & Chr(0) & _
Chr(0) & Chr(0) & _
Chr(0) & Chr(0) & _
Chr(0) & Chr(0) & _
Chr(0) & Chr(0) & _
Chr(0) & Chr(0)
' 创建图像数据
' 这里仅是一个示例,将图像数据设置为彩虹
imageData = ""
For i = 1 To imgHeight
For j = 1 To imgWidth
' BMP 中的像素数据是 BGR 格式
imageData = imageData & Chr(i Mod 256) & Chr((i + j) Mod 256) & Chr(j Mod 256)
Next
Next
' 将图像数据添加到 BMP 文件头后面
bmpData = bmpHeader & imageData
' 将 BMP 数据写入文件
Dim fs, outFile
Set fs = CreateObject("Scripting.FileSystemObject")
Set outFile = fs.CreateTextFile("output.bmp", True)
outFile.Write bmpData
outFile.Close