⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 makethumbnail.aspx.vb

📁 Module articles for Dot Net Nuke 3.x.x , 4.x.x
💻 VB
字号:
' DNN 2.0 B1 Photo Album
' Copyright (c) 2004
' by John D. Cooper ( John@johndcooper.com ) www.johndcooper.com - www.ideaca.om
'
' Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated 
' documentation files (the "Software"), to deal in the Software without restriction, including without limitation 
' the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and 
' to permit persons to whom the Software is furnished to do so, subject to the following conditions:
'
' The above copyright notice and this permission notice shall be included in all copies or substantial portions 
' of the Software.
'
' THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED 
' TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL 
' THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF 
' CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER 
' DEALINGS IN THE SOFTWARE.

Imports System.IO
Imports System.Drawing
Imports System.Drawing.Imaging
Imports System.Drawing.Drawing2D

Namespace EfficionConsulting.Articles
	Public Class MakeThumbnail
		Inherits System.Web.UI.Page

		Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load

			Dim objMemStream As MemoryStream
			Dim bteImage() As Byte

			Dim strFilepath As String
			Dim strCacheKey As String
			Dim iHeight As Integer
			Dim iWidth As Integer = 125

			If Not Request.Params("w") = "" Then
				iWidth = CType(Request.Params("w"), Integer)
			End If

			strFilepath = Server.MapPath(Request.Params("Image"))
			'Create the cache key of filename & width
			strCacheKey = strFilepath.Substring(strFilepath.LastIndexOf("\Portals\")) & iWidth
			If DataCache.GetCache(strCacheKey) Is Nothing Then
				'Get The Image
				'Create a new image
				Dim objImage As System.Drawing.Image
				Dim g As Graphics
				Dim b As System.Drawing.Bitmap
				objImage = System.Drawing.Image.FromFile(strFilepath)
					
				'Calculate New Size
				Dim dblRatio As Double = 0
				If objImage.Width > iWidth Then
					'Find out the height to width ratio
					dblRatio = objImage.Width / objImage.Height
					'apply height to width ratio to thumbnail
					iHeight = CType(iWidth / dblRatio, Integer)
				Else
					iWidth = objImage.Width
					iHeight = objImage.Height
				End If

				' create a new bitmap that will be the end result
				b = New System.Drawing.Bitmap(iWidth, iHeight, PixelFormat.Format24bppRgb)

				' create a graphics object to work with
				g = Graphics.FromImage(b)
				Dim x As Drawing.Image.GetThumbnailImageAbort

				' blank the image
				g.Clear(Color.White)

				'# resize!
				g.InterpolationMode = System.Drawing.Drawing2D.InterpolationMode.HighQualityBicubic
				g.DrawImage(objImage, 0, 0,iWidth, iHeight)

				' set the content type
				objMemStream = New MemoryStream
				b.Save(objMemStream, System.Drawing.Imaging.ImageFormat.Jpeg)

				'Cache the byte array for next time
				bteImage = objMemStream.ToArray()
				DataCache.SetCache(strCacheKey, bteImage)
				'Clean Up - without this there are some issues when trying to 
				'delete an image
				objImage.Dispose()
				g.Dispose()
				b.Dispose()

			Else
				'Load the image from cache
				bteImage = CType(DataCache.GetCache(strCacheKey), Byte())
				objMemStream = New MemoryStream(bteImage)
			End If
			Response.ContentType = "image/jpeg"
			objMemStream.WriteTo(Response.OutputStream)

		End Sub
		
		Private Function CalculateSize(ByVal currentWidth As integer,ByVal currentHeight As integer,ByVal newWidth As integer,ByRef newHeight As integer) As String
			
		End Function


#Region " Web Form Designer Generated Code "

		'This call is required by the Web Form Designer.
		<System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent()

		End Sub

		Private Sub Page_Init(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Init
			'CODEGEN: This method call is required by the Web Form Designer
			'Do not modify it using the code editor.
			InitializeComponent()
		End Sub

#End Region
	End Class
End Namespace

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -