Upload pictures and generate thumbnails

Source: Internet
Author: User
Tags end integer save file tostring
Upload | upload pictures | thumbnail Sub upimages ()
Dim Iname as String
If not (fileup. PostedFile is Nothing) Then
Dim namestr1 as String = (fileup. Postedfile.filename)
If LCase (fileup. PostedFile.ContentType.ToString ()) = "Image/pjpeg" Or LCase (fileup. PostedFile.ContentType.ToString ()) = "Image/jpg" Then
Dim J as Integer = Namestr1. LastIndexOf (".")
Dim newname as String = namestr1. Substring (j) ' Picture gets 輟 name
Iname = The filename of the CStr (NOW.TOFILETIMEUTC) ' random (not to be restored)
Dim newnames as String = iname + newname ' re-group filename
Dim i as Integer = namestr1. LastIndexOf ("\") + 1
Dim namestr as String = namestr1. Substring (i)
Fileup. Postedfile.saveas (Server.MapPath (imagelocal) + "\" + newnames) ' Save file to Imagelocal folder
' Generate thumbnails ()
Dim image, Simage as System.Drawing.Image
Image = System.Drawing.Image.FromStream (fileup. Postedfile.inputstream) ' Get the original artwork
Dim width as Decimal = image. Width over and over ' get the breadth of the original artwork
Dim height as Decimal = image. Height ' Gets the height of the original artwork
Dim Newwidth, newheight as Integer
' Set the height and width of the thumbnail
If (Width > height) Then
Newwidth = 150
Newheight = CInt (Height/width * 150)
Else
Newheight = 150
Newwidth = CInt (Width/height * 150)
End If
Simage = image. Getthumbnailimage (Newwidth, Newheight, nothing, IntPtr.Zero)
Dim x as Integer = SIMAGE.WIDTH/2-30
Dim y as Integer = simage.height-20
Dim output as Bitmap = New Bitmap (simage)
Dim g as Graphics = graphics.fromimage (Output)
' The thumbnail plus the License information ()
Dim fonts as New Font ("Courier new", 9)
g.DrawString ("Copyright information", fonts, New SolidBrush (color.red), X, y)
Output. Save (Server.MapPath ("simagelocal") + "\s_" + newnames, System.Drawing.Imaging.ImageFormat.Jpeg)
' Save thumbnail to simagelocal folder
Image1.visible=true;
Image1.imageurl = "simagelocal" + "\s_" + newnames

Else
Label1.Text = "Please choose a jpg type of picture"

End If
End If
End Sub





Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.