I searched for it on the Internet using C #. For more information, see. convert it to VB. NET.
' <Param name = "originalimagepath"> source image path (physical path) </param>
' <Param name = "thumbnailpath"> thumbnail path (physical path) </param>
' <Param name = "width"> thumbnail width </param>
' <Param name = "height"> thumbnail height </param>
' <Param name = "Mode"> how to generate a thumbnail </param>
Public Shared Sub makethumbnail () Sub Makethumbnail ( Byval Originalimagepath As String , Byval Thumbnailpath As String , Byval Width As Integer , Byval Height As Integer , Byval Mode As String )
Dim Originalimage As System. Drawing. Image
Originalimage = System. Drawing. image. fromfile (originalimagepath)
Dim Towidth As Integer = Width
Dim Toheight As Integer = Height
Dim X As Integer = 0
Dim Y As Integer = 0
Dim Ow As Integer = Originalimage. Width
Dim Oh As Integer = Originalimage. Height
Select Case Mode
Case " HW " ' Specify high-width Scaling (may be deformed)
Case " W " ' Specify width and height in proportion
Toheight = Originalimage. Height * Width / Originalimage. Width
Case " H " ' Specify height, width by proportion
Towidth = Originalimage. Width * Height / Originalimage. Height
Case " Cut " ' Specify height and width reduction (not deformed)
If Cdbl (Originalimage. width) / Cdbl (Originalimage. Height) > Cdbl (Towidth) / Cdbl (Toheight) Then
Oh = Originalimage. Height
Ow = Originalimage. Height * Towidth / Toheight
Y = 0
X = (Originalimage. Width - OW) / 2
Else
Ow = Originalimage. Width
Oh = Originalimage. Width * Height / Towidth
X = 0
Y = (Originalimage. Height - Oh) / 2
End If
Case Else
End Select
' Create a BMP Image
Dim Bitmap = New System. Drawing. Bitmap (towidth, toheight)
' Create a canvas
Dim G As Graphics = System. Drawing. Graphics. fromimage (Bitmap)
' Set a high quality Interpolation Method
G. interpolationmode = System. Drawing. drawing2d. interpolationmode. High
' Set high quality, low speed rendering Smoothness
G. smoothingmode = System. Drawing. drawing2d. smoothingmode. highquality
' Clear the canvas and fill it with a transparent background color
G. Clear (color. Transparent)
' Draw the specified part of the original image at the specified position and in the specified size
G. drawimage (originalimage, New Rectangle ( 0 , 0 , Towidth, toheight ), New Rectangle (X, Y, ow, oh), graphicsunit. pixel)
Try
' Save thumbnails in JPG format
Bitmap. Save (thumbnailpath)
Catch Ex As Exception
Throw Ex
Finally
Originalimage. Dispose ()
Bitmap. Dispose ()
G. Dispose ()
End Try
End sub
It is too bad to directly generate a thumbnail after using the original upload ..