请问怎样往 ADODB.Stream 写入二进制内容?
我使用ADODB.stream 读取图片,并拼合了一个图片验证码,字节流暂存在一个ADODB.Stream中
现在想往 图片中添加随机干扰点,使用ADODB.Stream.write CHRB(0) 添加不进去,3001错误:参数类型不正确,或者超出范围
请问应该怎么改,或者有其他的替代方案也可以
还没搞清楚VBS中的变量类型的朋友请不要随意回答,虚心学习也是一种美德,谢谢
'------------------------
'部分代码如下:
'-----------------------------------
function AddNoise(oStream,intDotCount)
'oStream 中存放的是一个4800字节的无BMP文件头的BMP图片,高20 像素,宽80像素
'debug 是 自定义的调试函数,用来输出调试信息到log文件里
if not IsObject(oStream) then exit function
dim intPosOrigin,intPos,intLength
dim i,j,intX,intY,intColor,bytColor
dim oStream2
set oStream2 = server.CreateObject("ADODB.Stream")
oStream2.Type = 1
oStream2.mode = 3
oStream2.open
intPosOrigin = oStream.position '记录ostream的原始游标位置
debug "当前位置",intPosOrigin
oStream.position = 0
intLength = int(oStream.size/3) '因为是BMP的图片,3个字节表示一个像素点
debug "流长度(像素/字节)",intLength & "/" & oStream.size
randomize
on error resume next
bytColor = oStream.read(3) '直接从oStream中读一个像素。此时typename(bytColor) = "byte()"
' bytColor = array(cbyte(0),cbyte(0) , cbyte(0)) ' 这样生成,typename(bytColor ) = "variable"
oStream.position = 0 ' 将oStream游标重置
j = Rnd() '生成随机数
if err then
debug "添加噪点2错误a",err.Description
err.Clear
end if
if j > 0.5 then ' 50%的可能性保持原来内容 oStream2.Write oStream.read(3) '
if err then
debug "添加噪点2错误b1-" & err.Number,err.Description
err.Clear
end if
else '写入干扰点
oStream2.write bytColor '------这里出错。不出错的时候显示一个只有最下一条线有内容而其他地方都是黑色的图片
if err then
debug "添加噪点2错误b21-" & err.Number,err.Description
err.Clear
end if
end if
if err then
debug "添加噪点2错误e",err.Description
err.Clear
end if
debug "ostream.size",oStream.size
debug "ostream2.size",oStream2.size
debug "ostream.position",ostream.position
debug "ostream2.position",ostream2.position
'读取剩余像素
oStream2.write oStream.read(oStream.size - intLength / 100 * 3)
debug "oStream2.size",oStream2.Size
'把临时对象中内容复制回去
oStream2.position = 0
ostream2.copyto oStream,intLength * 3
set AddNoise = oStream
if err then
debug "添加噪点2错误",err.Description
err.Clear
end if
end function