发信人: aldy7913(东瓜敏敏) 
整理人: i_am_trueman(2004-01-14 09:21:19), 站内信件
 | 
 
 
这可不是改变宽度属性,而是利用asp.net真正新建一个图片.
 
 
 
 主题:Re:图片在网页上的缩放功能 -动态生成例子 
  作 者: aldy7913 (东瓜敏敏) 2003-12-02 15:55:21  
 :0 :0     
 
 --------------------------------------------------------------------------------
  
 1:先在根目录下放一个win2000.gif的图片 
 2.拷贝代码成a.aspx(asp.net程序要安装netframe)放在根目录下. 
 3.在ie打:http://YourComputerName/a.aspx?src=win2000.gif&height=200&width=200 
 
 ---------- 
 <%@ Page Language="vb" Debug="True" %> 
 <%@ import namespace="System" %> 
 <%@ import namespace="System.Drawing" %> 
 <%@ import namespace="System.Drawing.Imaging" %> 
 <%@ import namespace="System.IO" %> 
 <script runat="server"> 
 
 Sub sendFile() 
 
  ' create New image and bitmap objects. Load the image file and put into a resized bitmap. 
  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"))) 
 
  ' Set the contenttype 
  if thisformat.equals(system.drawing.imaging.imageformat.Gif) then 
  response.contenttype="image/gif" 
  else 
  response.contenttype="image/jpeg" 
  end if 
 
 
 
  ' send the resized image to the viewer 
  imgOutput.save(response.outputstream, thisformat) ' output to the user 
 
  ' tidy up 
  g.dispose() 
  imgOutput.dispose() 
 
  end sub 
 
  Sub sendError() 
 
  ' if no height, width, src then output "error" 
  dim imgOutput as New bitmap(120, 120, pixelformat.format24bpprgb) 
  dim g as graphics = graphics.fromimage(imgOutput) ' create a New graphic object from the above bmp 
  g.clear(color.yellow) ' blank the image 
  g.drawString("ERROR!", New font("verdana",14,fontstyle.bold),systembrushes.windowtext, New pointF(2,2)) 
 
  ' Set the contenttype 
  response.contenttype="image/gif" 
 
  ' send the resized image to the viewer 
  imgOutput.save(response.outputstream, imageformat.gif) ' output to the user 
 
  ' tidy up 
  g.dispose() 
  imgOutput.dispose() 
 
 
  end sub 
 
 
  </script> 
 
 
 
  <% 
 
 
 ' make sure Nothing has gone to the client 
 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 
 
 %> 
 ---------------- 
 --
 
 作者:aldy7913【东瓜敏敏】
 ※ 来源: 网易虚拟社区 广州站.
  
 
 
  ----
  
  | 
 
 
 |