<p>利用FSO取得图像文件信息</p> <p>&#39;:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::<br /> &#39;::: BMP, GIF, JPG and PNG :::<br /> &#39;:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::<br /> &#39;:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::<br /> &#39;::: :::<br /> &#39;::: This function gets a specified number of bytes from any :::<br /> &#39;::: file, starting at the offset (base 1) :::<br /> &#39;::: :::<br /> &#39;::: Passed: :::<br /> &#39;::: flnm =&gt; Filespec of file to read :::<br /> &#39;::: offset =&gt; Offset at which to start reading :::<br /> &#39;::: bytes =&gt; How many bytes to read :::<br /> &#39;::: :::<br /> &#39;:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::<br /> function GetBytes(flnm, offset, bytes)<br /> Dim objFSO<br /> Dim objFTemp<br /> Dim objTextStream<br /> Dim lngSize<br /> on error resume next<br /> Set objFSO = CreateObject(&quot;Scripting.FileSystemObject&quot;)</p> <p>&#39; First, we get the filesize<br /> Set objFTemp = objFSO.GetFile(flnm)<br /> lngSize = objFTemp.Size<br /> set objFTemp = nothing<br /> fsoForReading = 1<br /> Set objTextStream = objFSO.OpenTextFile(flnm, fsoForReading)<br /> if offset &gt; 0 then<br /> strBuff = objTextStream.Read(offset - 1)<br /> end if<br /> if bytes = -1 then &#39; Get All!<br /> GetBytes = objTextStream.Read(lngSize) &#39;ReadAll<br /> else<br /> GetBytes = objTextStream.Read(bytes)<br /> end if<br /> objTextStream.Close<br /> set objTextStream = nothing<br /> set objFSO = nothing<br /> end function</p> <p>&#39;:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::<br /> &#39;::: :::<br /> &#39;::: Functions to convert two bytes to a numeric value (long) :::<br /> &#39;::: (both little-endian and big-endian) :::<br /> &#39;::: :::<br /> &#39;:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::<br /> function lngConvert(strTemp)<br /> lngConvert = clng(asc(left(strTemp, 1)) + ((asc(right(strTemp, 1)) * 256)))<br /> end function<br /> function lngConvert2(strTemp)<br /> lngConvert2 = clng(asc(right(strTemp, 1)) + ((asc(left(strTemp, 1)) * 256)))<br /> end function</p> <p>&#39;:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::<br /> &#39;::: :::<br /> &#39;::: This function does most of the real work. It will attempt :::<br /> &#39;::: to read any file, regardless of the extension, and will :::<br /> &#39;::: identify if it is a graphical image. :::<br /> &#39;::: :::<br /> &#39;::: Passed: :::<br /> &#39;::: flnm =&gt; Filespec of file to read :::<br /> &#39;::: width =&gt; width of image :::<br /> &#39;::: height =&gt; height of image :::<br /> &#39;::: depth =&gt; color depth (in number of colors) :::<br /> &#39;::: strImageType=&gt; type of image (e.g. GIF, BMP, etc.) :::<br /> &#39;::: :::<br /> &#39;:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::<br /> function gfxSpex(flnm, width, height, depth, strImageType)<br /> dim strPNG<br /> dim strGIF<br /> dim strBMP<br /> dim strType<br /> strType = &quot;&quot;<br /> strImageType = &quot;(unknown)&quot;<br /> gfxSpex = False<br /> strPNG = chr(137) &amp; chr(80) &amp; chr(78)<br /> strGIF = &quot;GIF&quot;<br /> strBMP = chr(66) &amp; chr(77)<br /> strType = GetBytes(flnm, 0, 3)<br /> if strType = strGIF then &#39; is GIF<br /> strImageType = &quot;GIF&quot;<br /> Width = lngConvert(GetBytes(flnm, 7, 2))<br /> Height = lngConvert(GetBytes(flnm, 9, 2))<br /> Depth = 2 ^ ((asc(GetBytes(flnm, 11, 1)) and 7) + 1)<br /> gfxSpex = True<br /> elseif left(strType, 2) = strBMP then &#39; is BMP<br /> strImageType = &quot;BMP&quot;<br /> Width = lngConvert(GetBytes(flnm, 19, 2))<br /> Height = lngConvert(GetBytes(flnm, 23, 2))<br /> Depth = 2 ^ (asc(GetBytes(flnm, 29, 1)))<br /> gfxSpex = True<br /> elseif strType = strPNG then &#39; Is PNG<br /> strImageType = &quot;PNG&quot;<br /> Width = lngConvert2(GetBytes(flnm, 19, 2))<br /> Height = lngConvert2(GetBytes(flnm, 23, 2))<br /> Depth = getBytes(flnm, 25, 2)<br /> select case asc(right(Depth,1))<br /> case 0<br /> Depth = 2 ^ (asc(left(Depth, 1)))<br /> gfxSpex = True<br /> case 2<br /> Depth = 2 ^ (asc(left(Depth, 1)) * 3)<br /> gfxSpex = True<br /> case 3<br /> Depth = 2 ^ (asc(left(Depth, 1))) &#39;8<br /> gfxSpex = True<br /> case 4<br /> Depth = 2 ^ (asc(left(Depth, 1)) * 2)<br /> gfxSpex = True<br /> case 6<br /> Depth = 2 ^ (asc(left(Depth, 1)) * 4)<br /> gfxSpex = True<br /> case else<br /> Depth = -1<br /> end select</p> <p>else<br /> strBuff = GetBytes(flnm, 0, -1) &#39; Get all bytes from file<br /> lngSize = len(strBuff)<br /> flgFound = 0<br /> strTarget = chr(255) &amp; chr(216) &amp; chr(255)<br /> flgFound = instr(strBuff, strTarget)<br /> if flgFound = 0 then<br /> exit function<br /> end if<br /> strImageType = &quot;JPG&quot;<br /> lngPos = flgFound + 2<br /> ExitLoop = false<br /> do while ExitLoop = False and</p>
返回顶部 留言