Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Sign in / Register
Toggle navigation
I
ImgGen
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Locked Files
Issues
0
Issues
0
List
Boards
Labels
Service Desk
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Security & Compliance
Security & Compliance
Dependency List
License Compliance
Packages
Packages
List
Container Registry
Analytics
Analytics
CI / CD
Code Review
Insights
Issues
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
MyCard
ImgGen
Commits
c8eaf52d
Commit
c8eaf52d
authored
Apr 29, 2020
by
mercury233
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
use multithread
parent
edcd0708
Changes
4
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
835 additions
and
744 deletions
+835
-744
DataManager.cs
DataManager.cs
+12
-698
ImageManager.cs
ImageManager.cs
+685
-0
ImgGen.csproj
ImgGen.csproj
+23
-0
Program.cs
Program.cs
+115
-46
No files found.
DataManager.cs
View file @
c8eaf52d
This diff is collapsed.
Click to expand it.
ImageManager.cs
0 → 100644
View file @
c8eaf52d
This diff is collapsed.
Click to expand it.
ImgGen.csproj
View file @
c8eaf52d
...
@@ -11,6 +11,21 @@
...
@@ -11,6 +11,21 @@
<TargetFrameworkProfile>
<TargetFrameworkProfile>
</TargetFrameworkProfile>
</TargetFrameworkProfile>
<FileAlignment>
512
</FileAlignment>
<FileAlignment>
512
</FileAlignment>
<PublishUrl>
publish\
</PublishUrl>
<Install>
true
</Install>
<InstallFrom>
Disk
</InstallFrom>
<UpdateEnabled>
false
</UpdateEnabled>
<UpdateMode>
Foreground
</UpdateMode>
<UpdateInterval>
7
</UpdateInterval>
<UpdateIntervalUnits>
Days
</UpdateIntervalUnits>
<UpdatePeriodically>
false
</UpdatePeriodically>
<UpdateRequired>
false
</UpdateRequired>
<MapFileExtensions>
true
</MapFileExtensions>
<ApplicationRevision>
0
</ApplicationRevision>
<ApplicationVersion>
1.0.0.%2a
</ApplicationVersion>
<IsWebBootstrapper>
false
</IsWebBootstrapper>
<UseApplicationTrust>
false
</UseApplicationTrust>
<BootstrapperEnabled>
true
</BootstrapperEnabled>
</PropertyGroup>
</PropertyGroup>
<PropertyGroup
Condition=
" '$(Configuration)|$(Platform)' == 'Debug|x86' "
>
<PropertyGroup
Condition=
" '$(Configuration)|$(Platform)' == 'Debug|x86' "
>
<DebugSymbols>
true
</DebugSymbols>
<DebugSymbols>
true
</DebugSymbols>
...
@@ -49,6 +64,7 @@
...
@@ -49,6 +64,7 @@
<ItemGroup>
<ItemGroup>
<Compile
Include=
"Data.cs"
/>
<Compile
Include=
"Data.cs"
/>
<Compile
Include=
"DataManager.cs"
/>
<Compile
Include=
"DataManager.cs"
/>
<Compile
Include=
"ImageManager.cs"
/>
<Compile
Include=
"Program.cs"
/>
<Compile
Include=
"Program.cs"
/>
</ItemGroup>
</ItemGroup>
<ItemGroup>
<ItemGroup>
...
@@ -59,6 +75,13 @@
...
@@ -59,6 +75,13 @@
<CopyToOutputDirectory>
PreserveNewest
</CopyToOutputDirectory>
<CopyToOutputDirectory>
PreserveNewest
</CopyToOutputDirectory>
</None>
</None>
</ItemGroup>
</ItemGroup>
<ItemGroup>
<BootstrapperPackage
Include=
"Microsoft.Net.Framework.3.5.SP1"
>
<Visible>
False
</Visible>
<ProductName>
.NET Framework 3.5 SP1
</ProductName>
<Install>
true
</Install>
</BootstrapperPackage>
</ItemGroup>
<Import
Project=
"$(MSBuildToolsPath)\Microsoft.CSHARP.Targets"
/>
<Import
Project=
"$(MSBuildToolsPath)\Microsoft.CSHARP.Targets"
/>
<ProjectExtensions>
<ProjectExtensions>
<VisualStudio
AllowExistingFolder=
"true"
/>
<VisualStudio
AllowExistingFolder=
"true"
/>
...
...
Program.cs
View file @
c8eaf52d
...
@@ -3,12 +3,25 @@ namespace ImgGen
...
@@ -3,12 +3,25 @@ namespace ImgGen
using
System
;
using
System
;
using
System.Collections.Generic
;
using
System.Collections.Generic
;
using
System.Drawing
;
using
System.Drawing
;
using
System.Drawing.Drawing2D
;
using
System.Drawing.Imaging
;
using
System.Drawing.Imaging
;
using
System.Drawing.Text
;
using
System.Drawing.Text
;
using
System.IO
;
using
System.IO
;
using
System.Threading
;
internal
class
Program
internal
class
Program
{
{
private
static
PrivateFontCollection
fontCollection
;
private
static
ImageCodecInfo
encoderInfo
;
private
static
EncoderParameters
encoderParams
;
private
static
bool
generateLarge
;
private
static
bool
generateSmall
;
private
static
bool
generateThumb
;
private
static
Queue
<
string
>
files
;
private
static
object
locker
=
new
object
();
private
static
ImageCodecInfo
GetEncoderInfo
(
string
mimeType
)
private
static
ImageCodecInfo
GetEncoderInfo
(
string
mimeType
)
{
{
ImageCodecInfo
[]
imageEncoders
=
ImageCodecInfo
.
GetImageEncoders
();
ImageCodecInfo
[]
imageEncoders
=
ImageCodecInfo
.
GetImageEncoders
();
...
@@ -22,8 +35,6 @@ namespace ImgGen
...
@@ -22,8 +35,6 @@ namespace ImgGen
return
null
;
return
null
;
}
}
private
static
PrivateFontCollection
fontCollection
;
public
static
FontFamily
GetFontFamily
(
string
fontName
)
public
static
FontFamily
GetFontFamily
(
string
fontName
)
{
{
try
try
...
@@ -51,6 +62,12 @@ namespace ImgGen
...
@@ -51,6 +62,12 @@ namespace ImgGen
{
{
fontCollection
.
AddFontFile
(
font
);
fontCollection
.
AddFontFile
(
font
);
}
}
encoderInfo
=
GetEncoderInfo
(
"image/jpeg"
);
encoderParams
=
new
EncoderParameters
(
1
);
EncoderParameter
parameter
=
new
EncoderParameter
(
Encoder
.
Quality
,
90L
);
encoderParams
.
Param
[
0
]
=
parameter
;
if
(
args
.
Length
>
0
)
if
(
args
.
Length
>
0
)
{
{
DataManager
.
InitialDatas
(
args
[
0
]);
DataManager
.
InitialDatas
(
args
[
0
]);
...
@@ -59,60 +76,112 @@ namespace ImgGen
...
@@ -59,60 +76,112 @@ namespace ImgGen
{
{
DataManager
.
InitialDatas
(
"../cards.cdb"
);
DataManager
.
InitialDatas
(
"../cards.cdb"
);
}
}
Encoder
quality
=
Encoder
.
Quality
;
ImageCodecInfo
encoderInfo
=
GetEncoderInfo
(
"image/jpeg"
);
files
=
new
Queue
<
string
>();
EncoderParameters
encoderParams
=
new
EncoderParameters
(
1
);
foreach
(
string
file
in
Directory
.
GetFiles
(
"./pico"
,
"*.png"
))
EncoderParameter
parameter
=
new
EncoderParameter
(
quality
,
90L
);
{
encoderParams
.
Param
[
0
]
=
parameter
;
files
.
Enqueue
(
file
);
List
<
string
>
files
=
new
List
<
string
>();
}
files
.
AddRange
(
Directory
.
GetFiles
(
"./pico"
,
"*.png"
));
foreach
(
string
file
in
Directory
.
GetFiles
(
"./pico"
,
"*.jpg"
))
files
.
AddRange
(
Directory
.
GetFiles
(
"./pico"
,
"*.jpg"
));
{
bool
generateLarge
=
System
.
Configuration
.
ConfigurationManager
.
AppSettings
[
"GenerateLarge"
]
!=
"False"
;
// true if AppSettings null
files
.
Enqueue
(
file
);
bool
generateSmall
=
System
.
Configuration
.
ConfigurationManager
.
AppSettings
[
"GenerateSmall"
]
==
"True"
;
}
bool
generateThumb
=
System
.
Configuration
.
ConfigurationManager
.
AppSettings
[
"GenerateThumb"
]
==
"True"
;
generateLarge
=
System
.
Configuration
.
ConfigurationManager
.
AppSettings
[
"GenerateLarge"
]
!=
"False"
;
// true if AppSettings null
generateSmall
=
System
.
Configuration
.
ConfigurationManager
.
AppSettings
[
"GenerateSmall"
]
==
"True"
;
generateThumb
=
System
.
Configuration
.
ConfigurationManager
.
AppSettings
[
"GenerateThumb"
]
==
"True"
;
if
(
generateLarge
)
if
(
generateLarge
)
Directory
.
CreateDirectory
(
"./picn"
);
Directory
.
CreateDirectory
(
"./picn"
);
if
(
generateSmall
)
if
(
generateSmall
)
Directory
.
CreateDirectory
(
"./pics"
);
Directory
.
CreateDirectory
(
"./pics"
);
if
(
generateThumb
)
if
(
generateThumb
)
Directory
.
CreateDirectory
(
"./pics/thumbnail"
);
Directory
.
CreateDirectory
(
"./pics/thumbnail"
);
foreach
(
string
str
in
files
)
for
(
int
i
=
0
;
i
<
Environment
.
ProcessorCount
;
i
++)
{
{
int
code
;
Thread
workThread
=
new
Thread
(
Worker
);
try
workThread
.
Start
();
{
}
code
=
int
.
Parse
(
Path
.
GetFileNameWithoutExtension
(
str
));
}
}
catch
private
static
void
Worker
()
{
{
continue
;
ImageManager
imageManager
;
}
lock
(
locker
)
string
fileName
=
code
.
ToString
()
+
".jpg"
;
{
Console
.
WriteLine
(
$"Generating
{
fileName
}
"
);
imageManager
=
new
ImageManager
();
Bitmap
image
=
DataManager
.
GetImage
(
code
);
imageManager
.
InitialDatas
();
if
(
image
==
null
)
}
{
while
(
true
)
Console
.
WriteLine
(
$"[
{
code
}
] generation failed"
);
{
continue
;
string
file
;
}
lock
(
locker
)
if
(
generateLarge
)
{
image
.
Save
(
"./picn/"
+
fileName
,
encoderInfo
,
encoderParams
);
}
if
(
generateSmall
)
{
Bitmap
bmp
=
DataManager
.
Zoom
(
image
,
177
,
254
);
bmp
.
Save
(
"./pics/"
+
fileName
,
encoderInfo
,
encoderParams
);
bmp
.
Dispose
();
}
if
(
generateThumb
)
{
{
Bitmap
bmp
=
DataManager
.
Zoom
(
image
,
44
,
64
);
if
(
files
.
Count
==
0
)
bmp
.
Save
(
"./pics/thumbnail/"
+
fileName
,
encoderInfo
,
encoderParams
)
;
return
;
bmp
.
Dispos
e
();
file
=
files
.
Dequeu
e
();
}
}
image
?.
Dispose
();
Genernate
(
file
,
imageManager
);
}
}
private
static
void
Genernate
(
string
srcName
,
ImageManager
imageManager
)
{
int
code
;
try
{
code
=
int
.
Parse
(
Path
.
GetFileNameWithoutExtension
(
srcName
));
}
catch
{
return
;
}
string
fileName
=
code
.
ToString
()
+
".jpg"
;
Console
.
WriteLine
(
$"Generating
{
fileName
}
"
);
Bitmap
image
=
imageManager
.
GetImage
(
code
);
if
(
image
==
null
)
{
Console
.
WriteLine
(
$"[
{
code
}
] generation failed"
);
return
;
}
if
(
generateLarge
)
{
image
.
Save
(
"./picn/"
+
fileName
,
encoderInfo
,
encoderParams
);
}
if
(
generateSmall
)
{
Bitmap
bmp
=
Zoom
(
image
,
177
,
254
);
bmp
.
Save
(
"./pics/"
+
fileName
,
encoderInfo
,
encoderParams
);
bmp
.
Dispose
();
}
if
(
generateThumb
)
{
Bitmap
bmp
=
Zoom
(
image
,
44
,
64
);
bmp
.
Save
(
"./pics/thumbnail/"
+
fileName
,
encoderInfo
,
encoderParams
);
bmp
.
Dispose
();
}
}
image
?.
Dispose
();
}
public
static
Bitmap
Zoom
(
Bitmap
sourceBitmap
,
int
newWidth
,
int
newHeight
)
{
if
(
sourceBitmap
!=
null
)
{
Bitmap
b
=
new
Bitmap
(
newWidth
,
newHeight
);
Graphics
graphics
=
Graphics
.
FromImage
(
b
);
graphics
.
CompositingQuality
=
CompositingQuality
.
HighQuality
;
graphics
.
SmoothingMode
=
SmoothingMode
.
HighQuality
;
graphics
.
PixelOffsetMode
=
PixelOffsetMode
.
HighQuality
;
graphics
.
InterpolationMode
=
InterpolationMode
.
HighQualityBicubic
;
Rectangle
newRect
=
new
Rectangle
(
0
,
0
,
newWidth
,
newHeight
);
Rectangle
srcRect
=
new
Rectangle
(
0
,
0
,
sourceBitmap
.
Width
,
sourceBitmap
.
Height
);
graphics
.
DrawImage
(
sourceBitmap
,
newRect
,
srcRect
,
GraphicsUnit
.
Pixel
);
graphics
.
Dispose
();
return
b
;
}
return
null
;
}
}
}
}
}
}
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment