Skip to content

Commit 7a68538

Browse files
committed
pic
1 parent 5038b82 commit 7a68538

File tree

8 files changed

+2490
-0
lines changed

8 files changed

+2490
-0
lines changed

c#/pic/CMakeLists.txt

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
cmake_minimum_required(VERSION 3.8)
2+
3+
project("gifApp" CSharp)
4+
5+
set(BASE_SRC_DIR ${PROJECT_SOURCE_DIR} CACHE STRING "BASE_SRC_DIR.")
6+
7+
#set(NET_VER_DIR "net35" CACHE STRING "BASE_SRC_DIR.")
8+
set(NET_VER_DIR "net40" CACHE STRING "BASE_SRC_DIR.")
9+
#set(NET_VER_DIR "net45" CACHE STRING "BASE_SRC_DIR.")
10+
#set(NET_VER_DIR "netstandard2.0" CACHE STRING "BASE_SRC_DIR.")
11+
12+
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -DDYZ_DBG")
13+
14+
include(CSharpUtilities)
15+
16+
file(GLOB GIF_DLL_SRC src/AnimatedGifEncoder.cs src/AssemblyInfo.cs src/GifDecoder.cs src/LZWEncoder.cs src/NeuQuant.cs)
17+
file(GLOB GIF_APP_SRC ExampleMain.cs)
18+
19+
add_library(libgif STATIC ${GIF_DLL_SRC})
20+
add_executable(gifApp ${GIF_APP_SRC} ${GIF_DLL_SRC})
21+
22+
# Set the .NET Framework version for the executable.
23+
# set_property(TARGET gifApp PROPERTY VS_DOTNET_TARGET_FRAMEWORK_VERSION "v4.6.1")
24+
25+
# Set the executable to be 32-bit.
26+
set_property(TARGET libgif PROPERTY WINDOWS_EXPORT_ALL_SYMBOLS TRUE)
27+
set_property(TARGET gifApp PROPERTY WIN32_EXECUTABLE TRUE)
28+
29+
30+
# Set the C# language version (defaults to 3.0).
31+
set(CMAKE_CSharp_FLAGS "/langversion:latest")
32+
33+
#csharp_set_windows_forms_properties()
34+
35+
# target_link_libraries(gifApp libgif)
36+
37+
# If necessary, link in other library/DLL references, such as 3rd party libraries.
38+
# set_property(TARGET gifApp PROPERTY VS_DOTNET_REFERENCE_gif lib/${NET_VER_DIR}/libgif.dll)
39+
40+
# Add in the .NET reference libraries.
41+
set_property(TARGET libgif PROPERTY VS_DOTNET_REFERENCES
42+
"Microsoft.CSharp"
43+
"System"
44+
"System.Core"
45+
"System.Data"
46+
"System.Drawing"
47+
"System.Windows.Forms"
48+
)
49+
set_property(TARGET gifApp PROPERTY VS_DOTNET_REFERENCES
50+
"Microsoft.CSharp"
51+
"System"
52+
"System.Core"
53+
"System.Data"
54+
"System.Drawing"
55+
"System.Windows.Forms"
56+
)
57+
SET_TARGET_PROPERTIES(${PROJECT_NAME} PROPERTIES LINK_FLAGS "/Release")
58+
59+

c#/pic/ExampleMain.cs

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
using System;
2+
using System.Drawing;
3+
using System.Drawing.Imaging;
4+
using System.IO;
5+
using Gif.Components;
6+
7+
namespace Example
8+
{
9+
class ExampleMain
10+
{
11+
[STAThread]
12+
static void Main(string[] args)
13+
{
14+
/* create Gif */
15+
//you should replace filepath
16+
String[] imageFilePaths = new String[] { "..\\..\\Res\\01.png", "..\\..\\Res\\02.png" }; //, "..\\..\\Res\\03.png" };
17+
String outputFilePath = "..\\..\\Res\\test.gif";
18+
AnimatedGifEncoder e = new AnimatedGifEncoder();
19+
20+
// read file as memorystream
21+
byte[] fileBytes = File.ReadAllBytes(outputFilePath);
22+
MemoryStream memStream = new MemoryStream(fileBytes);
23+
e.Start(memStream);
24+
e.SetDelay(500);
25+
//-1:no repeat,0:always repeat
26+
e.SetRepeat(0);
27+
for (int i = 0, count = imageFilePaths.Length; i < count; i++ )
28+
{
29+
e.AddFrame( Image.FromFile( imageFilePaths[i] ) );
30+
}
31+
e.Finish();
32+
/* extract Gif */
33+
string outputPath = "c:\\";
34+
GifDecoder gifDecoder = new GifDecoder();
35+
gifDecoder.Read( "c:\\test.gif" );
36+
for ( int i = 0, count = gifDecoder.GetFrameCount(); i < count; i++ )
37+
{
38+
Image frame = gifDecoder.GetFrame( i ); // frame i
39+
frame.Save( outputPath + Guid.NewGuid().ToString() + ".png", ImageFormat.Png );
40+
}
41+
}
42+
}
43+
}

c#/pic/build_vs.bat

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
rem call "C:\Program Files (x86)\Microsoft Visual Studio 14.0\VC\bin\vcvars32.bat"
2+
call "E:\Program Files (x86)\Microsoft Visual Studio\2019\Enterprise\VC\Auxiliary\Build\vcvars32.bat"
3+
4+
mkdir dyzbuild
5+
pushd dyzbuild
6+
rem cmake ..
7+
cmake -G "Visual Studio 16 2019" -A x64 ..
8+
MSBuild libgif.csproj /p:Configuration=Release /p:Platform=x64
9+
MSBuild gifApp.csproj /p:Configuration=Release /p:Platform=x64
10+
popd
11+
12+
for /f %%i in ('dir /s /b "*.dll"') do (copy %%i .\)
13+
for /f %%i in ('dir /s /b "*.exe"') do (copy %%i .\)
14+
pause

0 commit comments

Comments
 (0)