Thumbnails in ASP.NET
Previously, the thumbnail on the page must be used to use a third party component. Now, with .NET, thumbnails can be easily implemented. Below is an example of achieving thumbnails.
View example
The code is as follows: thumbnail.aspx
<%
@ Page Language
=
"
VB
"
Autoeventwireup
=
"
False
"
Codebehind
=
"
Thumbnail.aspx.vb
"
Inherits
=
"
askXWEB.THUMBNAIL
"
%>
DOCTYPE HTML PUBLIC "- // w3c // DTD HTML 4.0 Transitional // En"
>
<
HTML
>
<
HEAD
>
<
Title
>
Thumbnails in ASP.NET
Title
>
<
Meta
Content
= "Microsoft Visual Studio.net 7.0"
Name
= "Generator"
>
<
Meta
Content
= "Visual Basic 7.0"
Name
= "Code_Language"
>
<
Meta
Content
= "JavaScript"
Name
= "VS_DEFAULTCLIENTScript"
>
<
Meta
Content
= "http://schemas.microsoft.com/intellisense/ie5"
Name
= "vs_targetschema"
>
HEAD
>
<
Body
MS_Positioning
= "GridLayout"
>
<
ASP: Label
id
= "Label1"
Runat
= "Server"
>
ASP: Label
>
<
FORM
id
= "Form1"
Method
= "POST"
Runat
= "Server"
ENCTYPE
= "Multipart / Form-Data"
>
<
INPUT
Type
= "file"
Name
= "file"
Width
= "600"
> <
Br
> <
Br
>
<
ASP: Button
id
= "Button1"
Runat
= "Server"
>
ASP: Button
>
FORM
>
Body
>
HTML
>
After the code: Thumbnail.aspx.vbImports SystemImports System.WebImports System.DrawingImports System.IOImports System.Drawing.ImagingPublic Class Thumbnail Inherits System.Web.UI.Page Protected WithEvents Label1 As System.Web.UI.WebControls.Label Protected WithEvents Button1 As System.Web.ui.WebControls.Button # 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. InitializationComponent () end sub # end region private sub page_load (byval sender as system.Object, byval e as system.eventargs) Handles mybase.load label1.text = "
<
h3
>
Thumbnails in ASP.NET
h3
>
"Button1.Text =" thumbnail "upload and display End Sub Private Sub Button1_Click (ByVal sender As Object, ByVal e As System.EventArgs) Handles Button1.Click Dim MyFileColl As HttpFileCollection = HttpContext.Current.Request.Files Dim MyPostedFile As HttpPostedFile = Myfilecoll.item (0) if lcase (MyPostedFile.contentType.toString ()). Indexof ("Image")
<
0
Then Response.Write ( "invalid graphics format.") Exit Sub End If GetThumbNail (MyPostedFile.FileName, 100, 100, MyPostedFile.ContentType.ToString (), _ False, MyPostedFile.InputStream) End Sub Private Function GetImageType (ByVal strContentType As system.drawing.imaging.imageformat select, (). TOLOWER ()) Case "image / pjpeg" getImageType
= System.drawing.Imaging.ImageFormat.jpegcase "image / gif" getImageType
= System.drawing.Imaging.imageFormat.gif
Case "Image / BMP" getImageType
= System.drawing.Imaging.ImageFormat.bmp
Case "image / TIFF" GetImageType
= System.drawing.Imaging.imageFormat.tiff
Case "image / x-icon" getImageType
= System.drawing.Imaging.imageFormat.icon
Case "Image / X-PNG" getImageType
= System.drawing.Imaging.ImageFormat.png
Case "Image / X-EMF" getImageType
= System.drawing.Imaging.ImageFormat.emf
Case "Image / X-EXIF" GetImageType
= System.drawing.Imaging.ImageFormat.exif
Case "image / x-wmf" getImageType
= System.drawing.image.imageformat.wmf
Case Else GetImageType
= System.drawing.Imaging.imageFormat.MemoryBMP
End Select End Function Private Sub GetThumbNail (ByVal strFileName, ByVal iWidth, ByVal iheight, ByVal strContentType, _ ByVal blnGetFromFile, ByVal ImgStream) Dim oImg As Image If blnGetFromFile Then oImg
= Oimg.fromfile (StrfileName)
Else Oimg
= Oimg.fromstream (ImgStream)
END IF OIMG
= Oimg.getthumbnailImage (iWidth,
iHeight, Nothing, (New INTPTR ()). Zero) DIM STRGUID AS STRING
((New)
GUID ()). Newguid (). TOSTRING (). TouPper () DIM STRFILEXT AS STRING
= Strfilename.substring (Strfilename.lastIndexof ("."))
'Save to local' oimg.save (Server.MAppath ("Images") " Strguid StrfileExt, GetImageType (StrContentType)) 'Direct output URL file' response.redirect (" Images / " Strguid StrfileExT) ' The following is displayed on the screen Response.ContentType
= StrContentType
Dim memstream () 'Note: This can be erroneously used in different formats if you use Oimg.Save (Response.OutputStream, GetImageType (StrContentType))', such as PNG format. Oimg.save (Memstream, GetImageType (strconteTtype)) Memstream.WritReeto (Response.outputStream) End Subend Class