Vb.net 图像大小调整缓存
我有一个非常酷的图像大小调整器,可以动态调整图像大小,但我正在尝试修改它,以便它可以缓存图像 关于如何将Response.OutputStream保存到一个文件,我已经搜索了几个小时,但我所尝试的一切都没有奏效 代码如下:Vb.net 图像大小调整缓存,vb.net,image,caching,resize,Vb.net,Image,Caching,Resize,我有一个非常酷的图像大小调整器,可以动态调整图像大小,但我正在尝试修改它,以便它可以缓存图像 关于如何将Response.OutputStream保存到一个文件,我已经搜索了几个小时,但我所尝试的一切都没有奏效 代码如下: <%@ Page Language="VB" Debug="true" %> <%@ Import Namespace="System.Drawing" %> <%@Import Namespace="System.Drawing.Imaging
<%@ Page Language="VB" Debug="true" %>
<%@ Import Namespace="System.Drawing" %>
<%@Import Namespace="System.Drawing.Imaging" %>
<script language="VB" runat="server">
Function ThumbnailCallback() as Boolean
Return False
End Function
Sub Page_Load(sender as Object, e as EventArgs)
'Read in the image filename to create a thumbnail of
Dim imageUrl as string = Request.QueryString("img")
'Read in the width and height
Dim imageHeight as Integer = Request.QueryString("h")
Dim imageWidth as Integer = Request.QueryString("w")
Dim fullImg
Dim currDir
imageUrl = server.MapPath(imageUrl)
fullimg = imageUrl
Dim fullSizeImg as System.Drawing.Image
fullSizeImg = System.Drawing.Image.FromFile(imageURL)
fullSizeImg.RotateFlip(RotateFlipType.Rotate180FlipY)
fullSizeImg.RotateFlip(RotateFlipType.Rotate180FlipY)
Response.ContentType = "image/JPEG"
If imageHeight > 0 And imageWidth > 0 Then
Dim dummyCallBack As System.Drawing.Image.GetThumbnailImageAbort
Dim thumbNailImg As System.Drawing.Image
dummyCallBack = New System.Drawing.Image.GetThumbnailImageAbort(AddressOf ThumbnailCallback)
' if new image size is less than current image size
if (imageWidth < fullSizeImg.Width) or (imageHeight < fullSizeImg.Height) then
If (fullSizeImg.Width / imageWidth) > (fullSizeImg.Height / imageHeight) Then
'imageHeight = Round(fullSizeImg.Height * (imageWidth / fullSizeImg.Width), 0)
imageHeight = fullSizeImg.Height * (imageWidth / fullSizeImg.Width)
imageWidth = imageWidth
Else
'no need to modify height
'imageWidth = Round(fullSizeImg.Width * (imageHeight / fullSizeImg.Height), 0)
imageWidth = fullSizeImg.Width * (imageHeight / fullSizeImg.Height)
End If
thumbNailImg = fullSizeImg.GetThumbnailImage(imageWidth, imageHeight, dummyCallBack, IntPtr.Zero)
thumbNailImg.Save(Response.OutputStream, ImageFormat.Jpeg)
thumbNailImg.Dispose()
else
fullSizeImg.Save(Response.OutputStream, ImageFormat.Jpeg)
fullSizeImg.Dispose()
end if
Else
fullSizeImg.Save(Response.OutputStream, ImageFormat.Jpeg)
fullSizeImg.Dispose()
End If
End Sub
</script>
是否存在需要使用response.output流而无法直接保存到文件的原因?从system.image文档中可以看出,您应该能够直接保存到文件中 顺便说一句,该文件是这样使用的