二讀取和改變圖象文件大小
讀取圖片?直接使用HTML不就可以了?當然可以我們這裡只是提供一種選擇和方法來實現這一功能具體這一功能的使用我們可能需要在實踐中更多的學習先來看程序源代碼
<%
import all relevant namespaces %>
<%@ import namespace=
System
%>
<%@ import namespace=
System
Drawing
%>
<%@ import namespace=
System
Drawing
Imaging
%>
<%@ import namespace=
System
IO
%>
<script runat=
server
>
Sub sendFile()
dim g as System
Drawing
Image = System
Drawing
Image
FromFile(server
mappath(request(
src
)))
dim thisFormat=g
rawformat
dim imgOutput as New Bitmap(g
cint(request(
width
))
cint(request(
height
)))
if thisformat
equals(system
drawing
imaging
imageformat
Gif) then
response
contenttype=
image/gif
else
response
contenttype=
image/jpeg
end if
imgOutput
save(response
outputstream
thisformat)
g
dispose()
imgOutput
dispose()
end sub
Sub sendError()
dim imgOutput as New bitmap(
pixelformat
format
bpprgb)
dim g as graphics = graphics
fromimage(imgOutput)
g
clear(color
yellow)
g
drawString(
錯誤!
New font(
黑體
fontstyle
bold)
systembrushes
windowtext
New pointF(
))
response
contenttype=
image/gif
imgOutput
save(response
outputstream
imageformat
gif)
g
dispose()
imgOutput
dispose()
end sub
</script>
<%
response
clear
if request(
src
)=
or request(
height
)=
or request(
width
)=
then
call sendError()
else
if file
exists(server
mappath(request(
src
))) then
call sendFile()
else
call sendError()
end if
end if
response
end
%>
在以上的程序中我們看到兩個函數一個是SendFile這一函數主要功能為顯示服務器上的圖片該圖片的大小通過Width和Height設置同時程序會自動檢測圖片類型另外一個是SendError這一函數的主要功能為服務器上的圖片文件不存在時顯示錯誤信息這裡很有趣錯誤信息也是通過圖片給出的(如圖)
[] [] [] []
From:http://tw.wingwit.com/Article/program/net/201311/14864.html