基本信息
源码名称:vb将图片生成缩略图 示例源码
源码大小:0.21M
文件格式:.zip
开发语言:ASP
更新时间:2020-05-29
友情提示:(无需注册或充值,赞助后即可获取资源下载链接)
嘿,亲!知识可是无价之宝呢,但咱这精心整理的资料也耗费了不少心血呀。小小地破费一下,绝对物超所值哦!如有下载和支付问题,请联系我们QQ(微信同号):813200300
本次赞助数额为: 5 元×
微信扫码支付:5 元
×
请留下您的邮箱,我们将在2小时内将文件发到您的邮箱
源码介绍
Imports System.Drawing.Imaging Public Class Form1 ''' <summary> ''' 获取文件列表 ''' </summary> ''' <param name="sender"></param> ''' <param name="e"></param> Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click FolderBrowserDialog1.RootFolder = Environment.SpecialFolder.Desktop FolderBrowserDialog1.Description = "请选择图片文件夹" FolderBrowserDialog1.ShowNewFolderButton = True If FolderBrowserDialog1.ShowDialog = DialogResult.OK Then ListBox1.DataSource = IO.Directory.GetFiles(FolderBrowserDialog1.SelectedPath) End If End Sub ''' <summary> ''' 缩略图转换 ''' </summary> ''' <param name="sender"></param> ''' <param name="e"></param> Private Sub Button2_Click(sender As Object, e As EventArgs) Handles Button2.Click For Each c In ListBox1.Items If c <> "" Then GET_SC_IMG(c, 3) Next MessageBox.Show("缩略图转换完成!", "完成转换") End Sub ''' <summary> ''' 获取图片缩略图 ''' </summary> ''' <param name="old_path">原图文件路径</param> ''' <param name="sc">缩放比例</param> ''' <returns></returns> Function GET_SC_IMG(ByVal old_path As String, ByVal sc As Integer) As Boolean Try ''------------------------------------ ''文件不存在返回false If IO.File.Exists(old_path) = False Then Return False ''------------------------------------ ''保存缩略图文件路径 Dim f_name As String = Split(old_path, "\")(UBound(Split(old_path, "\"))) ''获取原文件名 Dim fld_path As String = $"{ old_path.Replace(f_name, "")}图片缩略图\" ''拼接缩略图文件夹路径 If IO.Directory.Exists(fld_path) = False Then IO.Directory.CreateDirectory(fld_path) ''创建缩略图文件夹 Dim new_path As String = $"{fld_path}sc_{f_name}" ''拼接缩略图文件路径 '------------------------------------- ''格式选择及判断 Dim img_form As ImageFormat = Nothing Select Case True Case old_path.ToUpper.Contains(".JPG") img_form = ImageFormat.Jpeg Case old_path.ToUpper.Contains(".BMP") img_form = ImageFormat.Bmp Case old_path.ToUpper.Contains(".PNG") img_form = ImageFormat.Png Case old_path.ToUpper.Contains(".ICO") img_form = ImageFormat.Icon Case old_path.ToUpper.Contains(".GIF") img_form = ImageFormat.Gif Case old_path.ToUpper.Contains(".TIFF") img_form = ImageFormat.Tiff Case old_path.ToUpper.Contains(".WMF") img_form = ImageFormat.Wmf Case old_path.ToUpper.Contains(".EXIF") img_form = ImageFormat.Exif Case old_path.ToUpper.Contains(".EMF") img_form = ImageFormat.Emf Case Else Return False ''不是以上格式表示为非图片 End Select ''-------------------------------------------- ''图片缩放 Using img As New Bitmap(old_path) Dim sc_w As Integer = img.Width / sc Dim sc_h As Integer = img.Height / sc Using n_img As New Bitmap(sc_w, sc_h) Dim grh As Graphics = Graphics.FromImage(n_img) grh.DrawImage(img, 0, 0, sc_w, sc_h) grh.Dispose() ''------------------------------------ ''保存图片 n_img.Save(new_path, img_form) Return True End Using End Using Catch ex As Exception Return False End Try End Function End Class