视频生成缩略图如何实现

Imports System.Drawing
Imports System.IO

 

Public Class admin_upimg
    Inherits Web.PageBase
    Protected WithEvents Btnup As System.Web.UI.WebControls.Button
    Protected WithEvents uplTheFile As System.Web.UI.HtmlControls.HtmlInputFile
    Protected WithEvents fileinfo As System.Web.UI.WebControls.Label

    Protected WithEvents chkslt As System.Web.UI.WebControls.CheckBox
    Protected WithEvents Txtslt As System.Web.UI.WebControls.TextBox
    Protected WithEvents Txt As System.Web.UI.WebControls.TextBox
    Protected WithEvents Chkonly As System.Web.UI.WebControls.CheckBox
    Protected WithEvents Chkshow As System.Web.UI.WebControls.CheckBox
    Protected WithEvents Txtfileadd As System.Web.UI.WebControls.TextBox

#Region " Web 窗体设计器生成的代码 "

    '该调用是 Web 窗体设计器所必需的。
    <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: 此方法调用是 Web 窗体设计器所必需的
        '不要使用代码编辑器修改它。
        InitializeComponent()
    End Sub

#End Region

    Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        '在此处放置初始化页的用户代码


    End Sub

    Private Sub Btnup_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Btnup.Click

        Txtfileadd.Text = ""
        Txtslt.Text = ""


        '-------------------------------------
        '
        '显示分类列表--list.aspx
        '
        '-------------------------------------
        If uplTheFile.PostedFile.ContentLength = 0 Then
            fileinfo.Visible = False
            Txtfileadd.Text = "文件长度不能为0"
            Exit Sub
        Else
            fileinfo.Visible = True
        End If
        Dim temnow As String = System.DateTime.Now.ToString("yyMMddhhffffff")


        '保存图片

        If Chkonly.Checked Then
        Else
            uplTheFile.PostedFile.SaveAs(Server.MapPath("../images/upload" + "/" + temnow + ".jpg"))
        End If
        '生成缩略图
        If chkslt.Checked Then
            Try
                Dim Image As System.Drawing.Image

                If Chkonly.Checked Then
                    Image = System.Drawing.Image.FromStream(uplTheFile.PostedFile.InputStream)
                Else
                    Image = System.Drawing.Image.FromFile(Server.MapPath("../images/upload" + "/" + temnow + ".jpg"))
                End If

                Dim width = Image.Width
                Dim height = Image.Height
                Dim newwidth As Integer
                Dim newheight As Integer

                If width > height Then
                    newwidth = 120
                    newheight = Image.Height / Image.Width * newwidth
                Else
                    newheight = 90
                    newwidth = Image.Width / Image.Height * newheight
                End If

                Dim callb As System.Drawing.Image.GetThumbnailImageAbort
                Dim anewimage = Image.GetThumbnailImage(newwidth, newheight, callb, New System.IntPtr)

                anewimage.Save(Server.MapPath("../images/upload" + "/" + temnow + "t" + ".jpg"))
                Image.Dispose()
                Txtslt.Text = "../images/upload" + "/" + temnow + "t" + ".jpg"

                Response.Write("<script>opener.SetTitleImg(""" & Txtslt.Text & """);</script>")
            Catch
                Txtslt.Text = "创建说略图失败,可能是你的图片格式不正确"
            End Try
        End If

        If Chkonly.Checked Then

        Else
            Txtfileadd.Text = "../images/upload" + "/" + temnow + ".jpg"
            If Chkshow.Checked Then
                Response.Write("<script>opener.SetBodyImg(""" & "<IMG sRc=" & Txtfileadd.Text & ">" & """);</script>")
            End If
        End If


        ' Dim FileSplit() As String = Split(uplTheFile.PostedFile.FileName, "/")
        'Dim FileName As String = FileSplit(FileSplit.Length - 1)
        ' Dim Exts() As String = Split(FileName, ".")
        '   Dim Ext As String = LCase(Exts(Exts.Length - 1))

    End Sub

 


    Private Sub Chkshow_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Chkshow.CheckedChanged

    End Sub
End Class
 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值