Skip to content

Commit

Permalink
init1
Browse files Browse the repository at this point in the history
  • Loading branch information
hontsev committed Sep 10, 2018
1 parent 9c7445f commit 3d1fd32
Show file tree
Hide file tree
Showing 13 changed files with 1,568 additions and 0 deletions.
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
/PhotoViewer/obj
/PhotoViewer/*.csproj
/PhotoViewer/bin
/.vs
25 changes: 25 additions & 0 deletions PhotoViewer.sln
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@

Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio 15
VisualStudioVersion = 15.0.27428.2015
MinimumVisualStudioVersion = 10.0.40219.1
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "PhotoViewer", "PhotoViewer\PhotoViewer.csproj", "{ED976A0A-C912-49C8-9A90-BF11381CAFF3}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Release|Any CPU = Release|Any CPU
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{ED976A0A-C912-49C8-9A90-BF11381CAFF3}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{ED976A0A-C912-49C8-9A90-BF11381CAFF3}.Debug|Any CPU.Build.0 = Debug|Any CPU
{ED976A0A-C912-49C8-9A90-BF11381CAFF3}.Release|Any CPU.ActiveCfg = Release|Any CPU
{ED976A0A-C912-49C8-9A90-BF11381CAFF3}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {3C4D356B-F825-4AEC-86EB-C7AAF86251AE}
EndGlobalSection
EndGlobal
157 changes: 157 additions & 0 deletions PhotoViewer/AnimateImage.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,157 @@
using System;
using System.Collections.Generic;
using System.Drawing;
using System.Drawing.Imaging;
using System.Linq;
using System.Text;

namespace PhotoViewer
{
/// <summary>
/// 表示一类带动画功能的图像。
/// </summary>
public class AnimateImage
{
Image image;
FrameDimension frameDimension;
/// <summary>
/// 动画当前帧发生改变时触发。
/// </summary>
public event EventHandler<EventArgs> OnFrameChanged;

/// <summary>
/// 实例化一个AnimateImage。
/// </summary>
/// <param name="img">动画图片。</param>
public AnimateImage(Image img)
{
image = img;

lock (image)
{
mCanAnimate = ImageAnimator.CanAnimate(image);
if (mCanAnimate)
{
Guid[] guid = image.FrameDimensionsList;
frameDimension = new FrameDimension(guid[0]);
mFrameCount = image.GetFrameCount(frameDimension);
}
}
}

bool mCanAnimate;
int mFrameCount = 1, mCurrentFrame = 0;

/// <summary>
/// 图片。
/// </summary>
public Image Image
{
get { return image; }
}

/// <summary>
/// 是否动画。
/// </summary>
public bool CanAnimate
{
get { return mCanAnimate; }
}

/// <summary>
/// 总帧数。
/// </summary>
public int FrameCount
{
get { return mFrameCount; }
}

/// <summary>
/// 播放的当前帧。
/// </summary>
public int CurrentFrame
{
get { return mCurrentFrame; }
}

/// <summary>
/// 播放这个动画。
/// </summary>
public void Play()
{
if (mCanAnimate)
{
lock (image)
{
ImageAnimator.Animate(image, new EventHandler(FrameChanged));
}
}
}

/// <summary>
/// 停止播放。
/// </summary>
public void Stop()
{
if (mCanAnimate)
{
lock (image)
{
ImageAnimator.StopAnimate(image, new EventHandler(FrameChanged));
}
}
}

public void Dispose()
{
OnFrameChanged = null;
try
{
Stop();

}
catch
{

}
lock (image)
{
if (image != null)
{
image.Dispose();
}
}


}

/// <summary>
/// 重置动画,使之停止在第0帧位置上。
/// </summary>
public void Reset()
{
if (mCanAnimate)
{
ImageAnimator.StopAnimate(image, new EventHandler(FrameChanged));
lock (image)
{
image.SelectActiveFrame(frameDimension, 0);
mCurrentFrame = 0;
}
}
}

private void FrameChanged(object sender, EventArgs e)
{
mCurrentFrame = mCurrentFrame + 1 >= mFrameCount ? 0 : mCurrentFrame + 1;
lock (image)
{
image.SelectActiveFrame(frameDimension, mCurrentFrame);
}
if (OnFrameChanged != null)
{
OnFrameChanged(image, e);
}
}
}
}
83 changes: 83 additions & 0 deletions PhotoViewer/Form1.Designer.cs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit 3d1fd32

Please sign in to comment.