-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
13 changed files
with
1,568 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
/PhotoViewer/obj | ||
/PhotoViewer/*.csproj | ||
/PhotoViewer/bin | ||
/.vs |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} | ||
} | ||
} | ||
} |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Oops, something went wrong.