当前位置:网站首页>VB.net GIF(制作、拆解——优化代码,类库——5)
VB.net GIF(制作、拆解——优化代码,类库——5)
2022-07-04 04:58:00 【小虞163】
我之前写过一篇文章,是制作和拆解GIF的文章,但是代码写的太复杂,我看完了自己都笑了
这一次在类库里完成gif的制作与拆解
先引用dll,名字叫:Gif.Components,可以在百度上搜索下载得到下载Gif.Components
https://dlc2.pconline.com.cn/filedown_1609054_10722470/Bv6pnYGm/pconline1517912109089.rar
下载完找到x86(32位),里面有Gif.Components.dll,如果需要x64,只要反编译得到C#源代码,再使用x64模式生成Gif.Components.dll(其实没有必要)
在类库中新建一个类,叫:GifMake
写:
Imports System.Drawing
Imports System.Windows.Forms
Public Class GifMake
Protected Image As Imaging.FrameDimension
Protected bmp As Bitmap
Protected bmp2() As Bitmap
Public AGE As New Gif.Components.AnimatedGifEncoder()
''' <summary>
''' 拆解gif,请直接调用
''' </summary>
''' <param name="gif">传入gif文件的绝对路径</param>
''' <param name="SavePath">传入保存文件的文件夹的绝对路径</param>
''' <param name="SaveName">保存文件的名称,可以不写,即直接传入""</param>
''' <param name="SaveStyle">保存文件的格式:例如.jpg;.png;.bmp</param>
''' <returns>null</returns>
Public Function SplitGif(gif As String, SavePath As String, SaveName As String, SaveStyle As String)
bmp = New Bitmap(gif)
Image = New Imaging.FrameDimension(bmp.FrameDimensionsList(0))
Dim bmp2(bmp.GetFrameCount(Image) - 1)
For i As Integer = 0 To bmp2.Count - 1
bmp.SelectActiveFrame(Image, i)
bmp2(i) = New Bitmap(bmp)
Next
For i As Integer = 0 To bmp2.Count - 1
bmp2(i).Save(SavePath & "\" & SaveName & i & "." & SaveStyle)
Next
Return vbNull
End Function
''' <summary>
''' 合成GIF
''' </summary>
''' <param name="sleep">每一帧间隔的毫秒数</param>
''' <returns>null</returns>
Public Function CraftGif(sleep As Integer)
Dim open As New OpenFileDialog
open.Filter = "图片文件|*.jpg;*.png;*.ico;*.bmp;*.jpeg;*.wmf;*.emf;*.gif"
open.Title = "选择图片"
open.Multiselect = True
open.ShowDialog()
If IO.File.Exists(open.FileName) = True Then
Dim count As Integer
count = open.FileNames.Count
Dim save As New SaveFileDialog
save.Filter = "GIF文件|*.gif"
save.Title = "保存GIF"
save.ShowDialog()
AGE.Start(save.FileName)
AGE.SetDelay(sleep)
AGE.SetRepeat(0)
Dim i As Integer = 0
While i < count
AGE.AddFrame(Drawing.Image.FromFile(open.FileNames(i)))
Math.Max(Threading.Interlocked.Increment(i), i - 1)
End While
AGE.Finish()
End If
Return vbNull
End Function
End Class
在主窗体调用
Private Sub Button7_Click(sender As Object, e As EventArgs) Handles Button7.Click
GDIgif.SplitGif("C:\Users\Administrator\Desktop\test.gif", "C:\Users\Administrator\Desktop", "", "jpg")
End Sub
Private Sub Button8_Click(sender As Object, e As EventArgs) Handles Button8.Click
GDIgif.CraftGif(200)
End Sub在函数段:SplitGif可以自己修改,这里没有什么正确的写法,可以仿照CraftGIF中写openFileDialog和saveFileDialog来保存图片
确实要比之前写的简洁了不少
边栏推荐
- flink1.13 sql基础语法(二)join操作
- 海力士EMMC5.0及5.1系列对比详解
- Flink1.13 basic SQL syntax (II) join operation
- 2022年T电梯修理操作证考试题库及模拟考试
- 【MATLAB】MATLAB 仿真模拟调制系统 — SSB 系统
- 【QT】定时器
- Notes on the paper "cross view transformers for real time map view semantic segmentation"
- Fault analysis | mongodb 5.0 reports an error, and the legal instruction solves it
- 企业级日志分析系统ELK(如果事与愿违那一定另有安排)
- appliedzkp zkevm(11)中的EVM Proof
猜你喜欢

2022 Guangdong provincial competition - code information acquisition and analysis flag

Integer type of C language

Trie数-字典树
![[interested reading] advantageous filtering modeling on long term user behavior sequences for click through rate pre](/img/3e/b5df691ca1790469eb1b4e8ea5b4c0.png)
[interested reading] advantageous filtering modeling on long term user behavior sequences for click through rate pre

How to build your own knowledge engine? Community open application

令人头痛的延时双删
![[QT] timer](/img/df/5db6af851ef19f33fd7e7a7ed46586.png)
[QT] timer

《Cross-view Transformers for real-time Map-view Semantic Segmentation》论文笔记

Daily question brushing record (12)

Graduation design of small programs -- small programs of food and recipes
随机推荐
空洞卷积、可变形卷积、可变形ROI Pooling
appliedzkp zkevm(11)中的EVM Proof
Zhongke Panyun - 2022 Guangxi reverse analysis ideas
Flink1.13 basic SQL syntax (II) join operation
【QT】定时器
Fault analysis | mongodb 5.0 reports an error, and the legal instruction solves it
Notes on the paper "cross view transformers for real time map view semantic segmentation"
抓包整理外篇fiddler———— 会话栏与过滤器
Annex III: scoring standard of the defender docx
远程桌面客户端 RDP
Using jsts in esmodule environment
[matlab] matlab simulation - simulate the AM modulation process of the modulation system
练习-冒泡排序
2022 t elevator repair operation certificate examination question bank and simulation examination
中科磐云—模块A 基础设施设置与安全加固 评分标准
Programming example of stm32f1 and stm32subeide -74hc595 drives 4-bit 7-segment nixie tube
简易零钱通
【MATLAB】MATLAB 仿真 — 窄带高斯白噪声
Analysis of classical pointer and array written test questions in C language
Capturing and sorting out external Fiddler -- Conversation bar and filter