* UGif: GIF图片解析类调试可用
This commit is contained in:
parent
5fbfe7cd4d
commit
6b2ea41f85
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
@ -787,6 +787,18 @@ namespace Sunny.UI
|
|||||||
return e.State == TreeNodeStates.Selected || e.State == TreeNodeStates.Focused ||
|
return e.State == TreeNodeStates.Selected || e.State == TreeNodeStates.Focused ||
|
||||||
e.State == (TreeNodeStates.Focused | TreeNodeStates.Selected);
|
e.State == (TreeNodeStates.Focused | TreeNodeStates.Selected);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
protected override void WndProc(ref Message m)
|
||||||
|
{
|
||||||
|
if (IsDisposed || Disposing) return;
|
||||||
|
if (m.Msg == Win32.User.WM_ERASEBKGND)
|
||||||
|
{
|
||||||
|
m.Result = IntPtr.Zero;
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
base.WndProc(ref m);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -1,4 +1,40 @@
|
|||||||
using System;
|
/******************************************************************************
|
||||||
|
* SunnyUI 开源控件库、工具类库、扩展类库、多页面开发框架。
|
||||||
|
* CopyRight (C) 2012-2021 ShenYongHua(沈永华).
|
||||||
|
* QQ群:56829229 QQ:17612584 EMail:SunnyUI@QQ.Com
|
||||||
|
*
|
||||||
|
* Blog: https://www.cnblogs.com/yhuse
|
||||||
|
* Gitee: https://gitee.com/yhuse/SunnyUI
|
||||||
|
* GitHub: https://github.com/yhuse/SunnyUI
|
||||||
|
*
|
||||||
|
* SunnyUI.dll can be used for free under the GPL-3.0 license.
|
||||||
|
* If you use this code, please keep this note.
|
||||||
|
* 如果您使用此代码,请保留此说明。
|
||||||
|
******************************************************************************
|
||||||
|
* 文件名称: UGif.cs
|
||||||
|
* 文件说明: GIF图片帮助类,可控制单帧显示图片
|
||||||
|
* 当前版本: V3.0
|
||||||
|
* 创建日期: 2021-07-17
|
||||||
|
*
|
||||||
|
* 2021-07-17: V3.0.5 增加文件说明
|
||||||
|
******************************************************************************/
|
||||||
|
|
||||||
|
/* 用法
|
||||||
|
private void button1_Click(object sender, System.EventArgs e)
|
||||||
|
{
|
||||||
|
Gif gif = new Gif("C:\\aa.gif");
|
||||||
|
//gif.Loop = true;//是否循环播放
|
||||||
|
gif.ImageChanged += Gif_ImageChanged;
|
||||||
|
gif.Active = gif.IsGif;//打开播放
|
||||||
|
}
|
||||||
|
|
||||||
|
private void Gif_ImageChanged(object sender, System.Drawing.Image image)
|
||||||
|
{
|
||||||
|
pictureBox1.Image = image;
|
||||||
|
}
|
||||||
|
*/
|
||||||
|
|
||||||
|
using System;
|
||||||
using System.Drawing;
|
using System.Drawing;
|
||||||
using System.Drawing.Imaging;
|
using System.Drawing.Imaging;
|
||||||
using System.Windows.Forms;
|
using System.Windows.Forms;
|
||||||
@ -29,30 +65,55 @@ namespace Sunny.UI
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void Dispose()
|
||||||
|
{
|
||||||
|
Active = false;
|
||||||
|
timer.Stop();
|
||||||
|
Image?.Dispose();
|
||||||
|
Image = null;
|
||||||
|
ShowImage?.Dispose();
|
||||||
|
ShowImage = null;
|
||||||
|
}
|
||||||
|
|
||||||
public bool Loop
|
public bool Loop
|
||||||
{
|
{
|
||||||
get; set;
|
get; set;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void Reset()
|
public void JumpToFrame(int frameIndex)
|
||||||
{
|
{
|
||||||
ImageCount = 0;
|
if (ImageCount == 0) return;
|
||||||
FrameIndex = 0;
|
if (frameIndex >= 0 && frameIndex < ImageCount)
|
||||||
Active = false;
|
{
|
||||||
|
if (ShowImage == null || ShowImage.Width != Image.Width || ShowImage.Height != Image.Height)
|
||||||
|
{
|
||||||
|
ShowImage?.Dispose();
|
||||||
|
ShowImage = new Bitmap(Image.Width, Image.Height);
|
||||||
|
}
|
||||||
|
|
||||||
|
FrameDimension fd = Image.GifFrameDimension();
|
||||||
|
Image.SelectActiveFrame(fd, frameIndex);
|
||||||
|
ShowImage.Graphics().DrawImage(Image, 0, 0, Image.Width, Image.Height);
|
||||||
|
ImageChanged?.Invoke(this, ShowImage);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private Image ShowImage;
|
||||||
|
|
||||||
private void Timer_Tick(object sender, EventArgs e)
|
private void Timer_Tick(object sender, EventArgs e)
|
||||||
{
|
{
|
||||||
timer.Stop();
|
timer.Stop();
|
||||||
|
|
||||||
if (Image == null)
|
if (Image == null)
|
||||||
{
|
{
|
||||||
Reset();
|
Active = false;
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (IsGif)
|
if (IsGif)
|
||||||
{
|
{
|
||||||
|
JumpToFrame(FrameIndex);
|
||||||
|
|
||||||
if (FrameIndex < ImageCount - 1)
|
if (FrameIndex < ImageCount - 1)
|
||||||
{
|
{
|
||||||
FrameIndex++;
|
FrameIndex++;
|
||||||
@ -68,17 +129,15 @@ namespace Sunny.UI
|
|||||||
active = false;
|
active = false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
FrameDimension fd = image.GifFrameDimension();
|
else
|
||||||
Image.SelectActiveFrame(fd, FrameIndex);
|
{
|
||||||
|
ImageChanged?.Invoke(this, Image);
|
||||||
}
|
}
|
||||||
|
|
||||||
ImageChanged?.Invoke(this, Image);
|
|
||||||
timer.Enabled = IsGif && active;
|
timer.Enabled = IsGif && active;
|
||||||
}
|
}
|
||||||
|
|
||||||
public Color BackColor { get; set; } = Color.White;
|
|
||||||
|
|
||||||
public delegate void OnImageChanged(object sender, Image image);
|
public delegate void OnImageChanged(object sender, Image image);
|
||||||
|
|
||||||
public event OnImageChanged ImageChanged;
|
public event OnImageChanged ImageChanged;
|
||||||
@ -87,7 +146,7 @@ namespace Sunny.UI
|
|||||||
|
|
||||||
private Image image;
|
private Image image;
|
||||||
|
|
||||||
private int ImageCount;
|
private int ImageCount => image == null ? 0 : image.GifFrameCount();
|
||||||
public bool IsGif => ImageCount > 0;
|
public bool IsGif => ImageCount > 0;
|
||||||
|
|
||||||
public Image Image
|
public Image Image
|
||||||
@ -95,20 +154,14 @@ namespace Sunny.UI
|
|||||||
get => image;
|
get => image;
|
||||||
set
|
set
|
||||||
{
|
{
|
||||||
Reset();
|
Active = false;
|
||||||
image = value;
|
image = value;
|
||||||
|
if (IsGif)
|
||||||
if (Image != null)
|
|
||||||
{
|
{
|
||||||
ImageCount = image.GifFrameCount();
|
int delay = image.GifFrameInterval();
|
||||||
|
if (delay > 0)
|
||||||
if (IsGif)
|
|
||||||
{
|
{
|
||||||
int delay = image.GifFrameInterval();
|
timer.Interval = delay;
|
||||||
if (delay > 0)
|
|
||||||
{
|
|
||||||
timer.Interval = delay;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -122,13 +175,6 @@ namespace Sunny.UI
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void Dispose()
|
|
||||||
{
|
|
||||||
Reset();
|
|
||||||
Image?.Dispose();
|
|
||||||
Image = null;
|
|
||||||
}
|
|
||||||
|
|
||||||
private int FrameIndex;
|
private int FrameIndex;
|
||||||
private bool active;
|
private bool active;
|
||||||
public bool Active
|
public bool Active
|
||||||
@ -136,7 +182,6 @@ namespace Sunny.UI
|
|||||||
get => active;
|
get => active;
|
||||||
set
|
set
|
||||||
{
|
{
|
||||||
ImageCount = 0;
|
|
||||||
FrameIndex = 0;
|
FrameIndex = 0;
|
||||||
active = value;
|
active = value;
|
||||||
timer.Enabled = value;
|
timer.Enabled = value;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user