Skip to content
This repository was archived by the owner on Dec 18, 2023. It is now read-only.

Commit ed07c58

Browse files
committed
Add gif
1 parent b73ff27 commit ed07c58

File tree

9 files changed

+204
-17
lines changed

9 files changed

+204
-17
lines changed

.github/workflows/codecheck.yml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ jobs:
1616
java-version: 1.11
1717
- uses: actions/checkout@v2
1818
with:
19-
fetch-depth: 0 # Shallow clones should be disabled for a better relevancy of analysis
19+
fetch-depth: 0
2020
- name: Setup .NET
2121
uses: actions/setup-dotnet@v1
2222
with:
@@ -42,10 +42,10 @@ jobs:
4242
dotnet tool update dotnet-sonarscanner --tool-path .\.sonar\scanner
4343
- name: Build and analyze
4444
env:
45-
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} # Needed to get PR information, if any
45+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
4646
SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }}
4747
shell: powershell
4848
run: |
4949
.\.sonar\scanner\dotnet-sonarscanner begin /k:"cookpopularcontrol" /o:"cookcsharp" /d:sonar.login="${{ secrets.SONAR_TOKEN }}" /d:sonar.host.url="https://sonarcloud.io"
50-
dotnet build .\ --configuration Release --no-restore
50+
dotnet build .\CookPopularControl.sln --configuration Release --no-restore
5151
.\.sonar\scanner\dotnet-sonarscanner end /d:sonar.login="${{ secrets.SONAR_TOKEN }}"

CookPopularCSharpToolkit/Communal/Extensions/ImageBitmapExtension.cs

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
using System;
1+
using CookPopularCSharpToolkit.Windows.Interop;
2+
using System;
23
using System.Drawing;
34
using System.Drawing.Imaging;
45
using System.IO;
@@ -23,9 +24,6 @@ namespace CookPopularCSharpToolkit.Communal
2324
/// </summary>
2425
public static class ImageBitmapExtension
2526
{
26-
[DllImport("Gdi32.dll")]
27-
private static extern bool DeleteObject(IntPtr intPtr);
28-
2927
/// <summary>
3028
/// Bitmap to ImageSource
3129
/// </summary>
@@ -41,7 +39,7 @@ public static ImageSource ToImageSource(this Bitmap bitmap)
4139
}
4240
finally
4341
{
44-
DeleteObject(intPtr);
42+
InteropMethods.DeleteObject(intPtr);
4543
}
4644
}
4745

CookPopularCSharpToolkit/Windows/Screenshot.cs

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
using System;
1+
using CookPopularCSharpToolkit.Windows.Interop;
2+
using System;
23
using System.Diagnostics.CodeAnalysis;
34
using System.Drawing;
45
using System.Drawing.Imaging;
@@ -37,8 +38,8 @@ private static class NativeMethods
3738
[DllImport("user32.dll")]
3839
internal static extern int ReleaseDC(IntPtr hWnd, IntPtr hDC);
3940

40-
[DllImport("gdi32.dll")]
41-
internal static extern bool DeleteObject(IntPtr hObject);
41+
//[DllImport("gdi32.dll")]
42+
//internal static extern bool DeleteObject(IntPtr hObject);
4243

4344
[DllImport("gdi32.dll")]
4445
internal static extern int GetDeviceCaps(IntPtr hDC, int nIndex);
@@ -162,7 +163,7 @@ public static BitmapSource ToBitmapSource(this Bitmap bitmap, bool disposing = f
162163
}
163164
finally
164165
{
165-
NativeMethods.DeleteObject(hBitmap);
166+
InteropMethods.DeleteObject(hBitmap);
166167
}
167168

168169
return source;
Lines changed: 116 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,116 @@
1+
using CookPopularCSharpToolkit.Windows.Interop;
2+
using System;
3+
using System.Collections.Generic;
4+
using System.Drawing;
5+
using System.IO;
6+
using System.Linq;
7+
using System.Runtime.InteropServices;
8+
using System.Text;
9+
using System.Threading.Tasks;
10+
using System.Windows;
11+
using System.Windows.Interop;
12+
using System.Windows.Media;
13+
using System.Windows.Media.Imaging;
14+
using System.Windows.Navigation;
15+
using System.Windows.Threading;
16+
17+
18+
19+
/*
20+
* Description:Gif
21+
* Author: Chance(a cook of write code)
22+
* Company: NCATest
23+
* Create Time:2021-12-24 21:05:57
24+
* .NET Version: 4.6
25+
* CLR Version: 4.0.30319.42000
26+
* Copyright (c) NCATest 2021 All Rights Reserved.
27+
*/
28+
namespace CookPopularControl.Controls
29+
{
30+
/// <summary>
31+
/// GIF动画
32+
/// </summary>
33+
/// <remarks>
34+
/// https://github.com/XamlAnimatedGif/XamlAnimatedGif
35+
/// </remarks>
36+
public class Gif : System.Windows.Controls.Image
37+
{
38+
private Bitmap _gifBitmap;
39+
private BitmapSource _bitmapSource;
40+
41+
/// <summary>
42+
/// Gif的路径
43+
/// </summary>
44+
public Uri GifSource
45+
{
46+
get { return (Uri)GetValue(GifSourceProperty); }
47+
set { SetValue(GifSourceProperty, value); }
48+
}
49+
/// <summary>
50+
/// 表示<see cref="GifSource"/>的依赖属性
51+
/// </summary>
52+
public static readonly DependencyProperty GifSourceProperty =
53+
DependencyProperty.Register("GifSource", typeof(Uri), typeof(Gif), new UIPropertyMetadata(default(Uri), GifSourcePropertyChanged));
54+
protected static void GifSourcePropertyChanged(DependencyObject obj, DependencyPropertyChangedEventArgs e)
55+
{
56+
if (obj is Gif gif)
57+
{
58+
gif.GifSource = e.NewValue as Uri;
59+
var stream = Application.GetResourceStream(gif.GifSource).Stream;
60+
gif._gifBitmap = new Bitmap(stream);
61+
gif._bitmapSource = gif.GetBitmapSource();
62+
gif.Source = gif._bitmapSource;
63+
gif.StartAnimate();
64+
}
65+
}
66+
67+
public void StartAnimate()
68+
{
69+
ImageAnimator.Animate(this._gifBitmap, this.OnFrameChanged);
70+
}
71+
72+
public void StopAnimate()
73+
{
74+
ImageAnimator.StopAnimate(this._gifBitmap, this.OnFrameChanged);
75+
}
76+
77+
private void OnFrameChanged(object sender, EventArgs e)
78+
{
79+
Dispatcher.BeginInvoke(DispatcherPriority.Normal, new Action(() =>
80+
{
81+
ImageAnimator.UpdateFrames();
82+
if (this._bitmapSource != null)
83+
{
84+
this._bitmapSource.Freeze();
85+
}
86+
87+
this._bitmapSource = this.GetBitmapSource();
88+
Source = this._bitmapSource;
89+
this.InvalidateVisual();
90+
}));
91+
}
92+
93+
/// <summary>
94+
/// BitmapSource用于显示System.drawing.bitmap中的图像的帧
95+
/// </summary>
96+
/// <returns></returns>
97+
private BitmapSource GetBitmapSource()
98+
{
99+
IntPtr handle = IntPtr.Zero;
100+
101+
try
102+
{
103+
handle = this._gifBitmap.GetHbitmap();
104+
this._bitmapSource = Imaging.CreateBitmapSourceFromHBitmap(handle, IntPtr.Zero, System.Windows.Int32Rect.Empty, BitmapSizeOptions.FromEmptyOptions());
105+
}
106+
finally
107+
{
108+
if (handle != IntPtr.Zero)
109+
{
110+
InteropMethods.DeleteObject(handle);
111+
}
112+
}
113+
return this._bitmapSource;
114+
}
115+
}
116+
}

CookPopularControl/CookPopularControl.xml

Lines changed: 24 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

MvvmTestDemo/App.xaml.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,8 @@ public partial class App : Application
2121

2222
protected override void OnStartup(StartupEventArgs e)
2323
{
24-
SplashScreen ss = new SplashScreen("Resources/Gif/cook.gif");
25-
ss.Show(true, true);
24+
//SplashScreen ss = new SplashScreen("Resources/Gif/cook.gif");
25+
//ss.Show(true, true);
2626

2727
base.OnStartup(e);
2828

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
<UserControl x:Class="MvvmTestDemo.DemoViews.PictureDemo"
2+
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
3+
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
4+
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
5+
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
6+
xmlns:local="clr-namespace:MvvmTestDemo.DemoViews"
7+
xmlns:pc="https://Chance.CookPopularControl/2021/xaml"
8+
mc:Ignorable="d"
9+
d:DesignHeight="450" d:DesignWidth="800">
10+
11+
<Grid>
12+
<pc:Gif GifSource="./Resources/Gif/cook.gif"/>
13+
</Grid>
14+
15+
</UserControl>
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using System.Linq;
4+
using System.Text;
5+
using System.Threading.Tasks;
6+
using System.Windows;
7+
using System.Windows.Controls;
8+
using System.Windows.Data;
9+
using System.Windows.Documents;
10+
using System.Windows.Input;
11+
using System.Windows.Media;
12+
using System.Windows.Media.Imaging;
13+
using System.Windows.Navigation;
14+
using System.Windows.Shapes;
15+
16+
namespace MvvmTestDemo.DemoViews
17+
{
18+
/// <summary>
19+
/// PictureDemo.xaml 的交互逻辑
20+
/// </summary>
21+
public partial class PictureDemo : UserControl
22+
{
23+
public PictureDemo()
24+
{
25+
InitializeComponent();
26+
}
27+
}
28+
}

ReadMe.md

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,18 +2,23 @@
22

33
# Welcome to CookPopularControl
44

5-
[![Nuget Publish](https://github.com/chancezheng/CookPopularControl/actions/workflows/nuget-push.yml/badge.svg)](https://github.com/chancezheng/CookPopularControl/actions/workflows/nuget-push.yml) [![qq群](https://img.shields.io/badge/qq-658794308-red.svg)](https://jq.qq.com/?_wv=1027&k=hVVHKJ1V)
5+
[![Nuget Publish](https://github.com/chancezheng/CookPopularControl/actions/workflows/nuget-push.yml/badge.svg)](https://github.com/chancezheng/CookPopularControl/actions/workflows/nuget-push.yml)
6+
[![Quality Gate Status](https://sonarcloud.io/api/project_badges/measure?project=campaigns-auxiliary-service&metric=alert_status)](https://sonarcloud.io/summary/new_code?id=campaigns-auxiliary-service)
7+
[![qq群](https://img.shields.io/badge/qq-658794308-red.svg)](https://jq.qq.com/?_wv=1027&k=hVVHKJ1V)
68

79
[![](https://img.shields.io/badge/Author-写代码的厨子-brightgreen.svg)](https://gitee.com/cook-csharp/CookPopularControl) [![license](https://img.shields.io/badge/license-Apache2.0-brightgreen.svg)](https://gitee.com/cook-csharp/CookPopularControl/blob/chance_dev/LICENSE) [![nuget](https://img.shields.io/nuget/v/CookPopularControl.svg)](https://www.nuget.org/packages/CookPopularControl) [![nuget](https://img.shields.io/nuget/dt/CookPopularControl.svg)](https://www.nuget.org/packages/CookPopularControl) [![Build Status](https://dev.azure.com/407042815/vue-mapvgl/_apis/build/status/vue-mapvgl-Node.js%20With%20Grunt-CI?branchName=master)]()
810

911
[![Gitee stars](https://gitee.com/cook-csharp/CookPopularControl/badge/star.svg?theme=dark)](https://gitee.com/cook-csharp/CookPopularControl) [![Gitee forks](https://gitee.com/cook-csharp/CookPopularControl/badge/fork.svg?theme=dark)](https://gitee.com/cook-csharp/CookPopularControl)
1012
[![Github stars](https://img.shields.io/github/stars/chancezheng/CookPopularControl.svg?color=red&&logo=github)](https://github.com/chancezheng/CookPopularControl) [![Github forks](https://img.shields.io/github/forks/chancezheng/CookPopularControl.svg?color=red&&logo=github)](https://github.com/chancezheng/CookPopularControl)
1113

12-
## 介绍
14+
## **介绍**
1315
CookPopularControl是支持.NetFramework4.6.1与.Net5.0的WPF控件库,其中参考了一些资料,目前提供了近70款左右的控件,还在更新中,感兴趣的可以持续关注下,如果你的项目用到此库,不要忘记点个赞,有问题可加QQ群交流:658794308,欢迎大家参与开发和指出问题,谢谢!
1416
***
1517

16-
## 使用
18+
## **代码检测**
19+
[![效果](https://sonarcloud.io/api/project_badges/quality_gate?project=campaigns-auxiliary-service)](https://sonarcloud.io/project/configuration?analysisMode=GitHubActions&id=chancezheng_CookPopularControl)
20+
21+
## **使用**
1722
- Install-Package CookPopularControl -Version 1.0.1.1
1823

1924
- 添加如下代码即可全部引用

0 commit comments

Comments
 (0)