Revize 23e9ca21
Přidáno uživatelem Alex Konig před téměř 4 roky(ů)
TextureEditing/.gitignore | ||
---|---|---|
1 |
|
|
2 |
# Created by https://www.toptal.com/developers/gitignore/api/visualstudio |
|
3 |
# Edit at https://www.toptal.com/developers/gitignore?templates=visualstudio |
|
4 |
|
|
5 |
### VisualStudio ### |
|
6 |
## Ignore Visual Studio temporary files, build results, and |
|
7 |
## files generated by popular Visual Studio add-ons. |
|
8 |
## |
|
9 |
## Get latest from https://github.com/github/gitignore/blob/master/VisualStudio.gitignore |
|
10 |
|
|
11 |
# User-specific files |
|
12 |
*.rsuser |
|
13 |
*.suo |
|
14 |
*.user |
|
15 |
*.userosscache |
|
16 |
*.sln.docstates |
|
17 |
|
|
18 |
# User-specific files (MonoDevelop/Xamarin Studio) |
|
19 |
*.userprefs |
|
20 |
|
|
21 |
# Mono auto generated files |
|
22 |
mono_crash.* |
|
23 |
|
|
24 |
# Build results |
|
25 |
[Dd]ebug/ |
|
26 |
[Dd]ebugPublic/ |
|
27 |
[Rr]elease/ |
|
28 |
[Rr]eleases/ |
|
29 |
x64/ |
|
30 |
x86/ |
|
31 |
[Ww][Ii][Nn]32/ |
|
32 |
[Aa][Rr][Mm]/ |
|
33 |
[Aa][Rr][Mm]64/ |
|
34 |
bld/ |
|
35 |
[Bb]in/ |
|
36 |
[Oo]bj/ |
|
37 |
[Ll]og/ |
|
38 |
[Ll]ogs/ |
|
39 |
|
|
40 |
# Visual Studio 2015/2017 cache/options directory |
|
41 |
.vs/ |
|
42 |
# Uncomment if you have tasks that create the project's static files in wwwroot |
|
43 |
#wwwroot/ |
|
44 |
|
|
45 |
# Visual Studio 2017 auto generated files |
|
46 |
Generated\ Files/ |
|
47 |
|
|
48 |
# MSTest test Results |
|
49 |
[Tt]est[Rr]esult*/ |
|
50 |
[Bb]uild[Ll]og.* |
|
51 |
|
|
52 |
# NUnit |
|
53 |
*.VisualState.xml |
|
54 |
TestResult.xml |
|
55 |
nunit-*.xml |
|
56 |
|
|
57 |
# Build Results of an ATL Project |
|
58 |
[Dd]ebugPS/ |
|
59 |
[Rr]eleasePS/ |
|
60 |
dlldata.c |
|
61 |
|
|
62 |
# Benchmark Results |
|
63 |
BenchmarkDotNet.Artifacts/ |
|
64 |
|
|
65 |
# .NET Core |
|
66 |
project.lock.json |
|
67 |
project.fragment.lock.json |
|
68 |
artifacts/ |
|
69 |
|
|
70 |
# ASP.NET Scaffolding |
|
71 |
ScaffoldingReadMe.txt |
|
72 |
|
|
73 |
# StyleCop |
|
74 |
StyleCopReport.xml |
|
75 |
|
|
76 |
# Files built by Visual Studio |
|
77 |
*_i.c |
|
78 |
*_p.c |
|
79 |
*_h.h |
|
80 |
*.ilk |
|
81 |
*.meta |
|
82 |
*.obj |
|
83 |
*.iobj |
|
84 |
*.pch |
|
85 |
*.pdb |
|
86 |
*.ipdb |
|
87 |
*.pgc |
|
88 |
*.pgd |
|
89 |
*.rsp |
|
90 |
*.sbr |
|
91 |
*.tlb |
|
92 |
*.tli |
|
93 |
*.tlh |
|
94 |
*.tmp |
|
95 |
*.tmp_proj |
|
96 |
*_wpftmp.csproj |
|
97 |
*.log |
|
98 |
*.vspscc |
|
99 |
*.vssscc |
|
100 |
.builds |
|
101 |
*.pidb |
|
102 |
*.svclog |
|
103 |
*.scc |
|
104 |
|
|
105 |
# Chutzpah Test files |
|
106 |
_Chutzpah* |
|
107 |
|
|
108 |
# Visual C++ cache files |
|
109 |
ipch/ |
|
110 |
*.aps |
|
111 |
*.ncb |
|
112 |
*.opendb |
|
113 |
*.opensdf |
|
114 |
*.sdf |
|
115 |
*.cachefile |
|
116 |
*.VC.db |
|
117 |
*.VC.VC.opendb |
|
118 |
|
|
119 |
# Visual Studio profiler |
|
120 |
*.psess |
|
121 |
*.vsp |
|
122 |
*.vspx |
|
123 |
*.sap |
|
124 |
|
|
125 |
# Visual Studio Trace Files |
|
126 |
*.e2e |
|
127 |
|
|
128 |
# TFS 2012 Local Workspace |
|
129 |
$tf/ |
|
130 |
|
|
131 |
# Guidance Automation Toolkit |
|
132 |
*.gpState |
|
133 |
|
|
134 |
# ReSharper is a .NET coding add-in |
|
135 |
_ReSharper*/ |
|
136 |
*.[Rr]e[Ss]harper |
|
137 |
*.DotSettings.user |
|
138 |
|
|
139 |
# TeamCity is a build add-in |
|
140 |
_TeamCity* |
|
141 |
|
|
142 |
# DotCover is a Code Coverage Tool |
|
143 |
*.dotCover |
|
144 |
|
|
145 |
# AxoCover is a Code Coverage Tool |
|
146 |
.axoCover/* |
|
147 |
!.axoCover/settings.json |
|
148 |
|
|
149 |
# Coverlet is a free, cross platform Code Coverage Tool |
|
150 |
coverage*[.json, .xml, .info] |
|
151 |
|
|
152 |
# Visual Studio code coverage results |
|
153 |
*.coverage |
|
154 |
*.coveragexml |
|
155 |
|
|
156 |
# NCrunch |
|
157 |
_NCrunch_* |
|
158 |
.*crunch*.local.xml |
|
159 |
nCrunchTemp_* |
|
160 |
|
|
161 |
# MightyMoose |
|
162 |
*.mm.* |
|
163 |
AutoTest.Net/ |
|
164 |
|
|
165 |
# Web workbench (sass) |
|
166 |
.sass-cache/ |
|
167 |
|
|
168 |
# Installshield output folder |
|
169 |
[Ee]xpress/ |
|
170 |
|
|
171 |
# DocProject is a documentation generator add-in |
|
172 |
DocProject/buildhelp/ |
|
173 |
DocProject/Help/*.HxT |
|
174 |
DocProject/Help/*.HxC |
|
175 |
DocProject/Help/*.hhc |
|
176 |
DocProject/Help/*.hhk |
|
177 |
DocProject/Help/*.hhp |
|
178 |
DocProject/Help/Html2 |
|
179 |
DocProject/Help/html |
|
180 |
|
|
181 |
# Click-Once directory |
|
182 |
publish/ |
|
183 |
|
|
184 |
# Publish Web Output |
|
185 |
*.[Pp]ublish.xml |
|
186 |
*.azurePubxml |
|
187 |
# Note: Comment the next line if you want to checkin your web deploy settings, |
|
188 |
# but database connection strings (with potential passwords) will be unencrypted |
|
189 |
*.pubxml |
|
190 |
*.publishproj |
|
191 |
|
|
192 |
# Microsoft Azure Web App publish settings. Comment the next line if you want to |
|
193 |
# checkin your Azure Web App publish settings, but sensitive information contained |
|
194 |
# in these scripts will be unencrypted |
|
195 |
PublishScripts/ |
|
196 |
|
|
197 |
# NuGet Packages |
|
198 |
*.nupkg |
|
199 |
# NuGet Symbol Packages |
|
200 |
*.snupkg |
|
201 |
# The packages folder can be ignored because of Package Restore |
|
202 |
**/[Pp]ackages/* |
|
203 |
# except build/, which is used as an MSBuild target. |
|
204 |
!**/[Pp]ackages/build/ |
|
205 |
# Uncomment if necessary however generally it will be regenerated when needed |
|
206 |
#!**/[Pp]ackages/repositories.config |
|
207 |
# NuGet v3's project.json files produces more ignorable files |
|
208 |
*.nuget.props |
|
209 |
*.nuget.targets |
|
210 |
|
|
211 |
# Microsoft Azure Build Output |
|
212 |
csx/ |
|
213 |
*.build.csdef |
|
214 |
|
|
215 |
# Microsoft Azure Emulator |
|
216 |
ecf/ |
|
217 |
rcf/ |
|
218 |
|
|
219 |
# Windows Store app package directories and files |
|
220 |
AppPackages/ |
|
221 |
BundleArtifacts/ |
|
222 |
Package.StoreAssociation.xml |
|
223 |
_pkginfo.txt |
|
224 |
*.appx |
|
225 |
*.appxbundle |
|
226 |
*.appxupload |
|
227 |
|
|
228 |
# Visual Studio cache files |
|
229 |
# files ending in .cache can be ignored |
|
230 |
*.[Cc]ache |
|
231 |
# but keep track of directories ending in .cache |
|
232 |
!?*.[Cc]ache/ |
|
233 |
|
|
234 |
# Others |
|
235 |
ClientBin/ |
|
236 |
~$* |
|
237 |
*~ |
|
238 |
*.dbmdl |
|
239 |
*.dbproj.schemaview |
|
240 |
*.jfm |
|
241 |
*.pfx |
|
242 |
*.publishsettings |
|
243 |
orleans.codegen.cs |
|
244 |
|
|
245 |
# Including strong name files can present a security risk |
|
246 |
# (https://github.com/github/gitignore/pull/2483#issue-259490424) |
|
247 |
#*.snk |
|
248 |
|
|
249 |
# Since there are multiple workflows, uncomment next line to ignore bower_components |
|
250 |
# (https://github.com/github/gitignore/pull/1529#issuecomment-104372622) |
|
251 |
#bower_components/ |
|
252 |
|
|
253 |
# RIA/Silverlight projects |
|
254 |
Generated_Code/ |
|
255 |
|
|
256 |
# Backup & report files from converting an old project file |
|
257 |
# to a newer Visual Studio version. Backup files are not needed, |
|
258 |
# because we have git ;-) |
|
259 |
_UpgradeReport_Files/ |
|
260 |
Backup*/ |
|
261 |
UpgradeLog*.XML |
|
262 |
UpgradeLog*.htm |
|
263 |
ServiceFabricBackup/ |
|
264 |
*.rptproj.bak |
|
265 |
|
|
266 |
# SQL Server files |
|
267 |
*.mdf |
|
268 |
*.ldf |
|
269 |
*.ndf |
|
270 |
|
|
271 |
# Business Intelligence projects |
|
272 |
*.rdl.data |
|
273 |
*.bim.layout |
|
274 |
*.bim_*.settings |
|
275 |
*.rptproj.rsuser |
|
276 |
*- [Bb]ackup.rdl |
|
277 |
*- [Bb]ackup ([0-9]).rdl |
|
278 |
*- [Bb]ackup ([0-9][0-9]).rdl |
|
279 |
|
|
280 |
# Microsoft Fakes |
|
281 |
FakesAssemblies/ |
|
282 |
|
|
283 |
# GhostDoc plugin setting file |
|
284 |
*.GhostDoc.xml |
|
285 |
|
|
286 |
# Node.js Tools for Visual Studio |
|
287 |
.ntvs_analysis.dat |
|
288 |
node_modules/ |
|
289 |
|
|
290 |
# Visual Studio 6 build log |
|
291 |
*.plg |
|
292 |
|
|
293 |
# Visual Studio 6 workspace options file |
|
294 |
*.opt |
|
295 |
|
|
296 |
# Visual Studio 6 auto-generated workspace file (contains which files were open etc.) |
|
297 |
*.vbw |
|
298 |
|
|
299 |
# Visual Studio LightSwitch build output |
|
300 |
**/*.HTMLClient/GeneratedArtifacts |
|
301 |
**/*.DesktopClient/GeneratedArtifacts |
|
302 |
**/*.DesktopClient/ModelManifest.xml |
|
303 |
**/*.Server/GeneratedArtifacts |
|
304 |
**/*.Server/ModelManifest.xml |
|
305 |
_Pvt_Extensions |
|
306 |
|
|
307 |
# Paket dependency manager |
|
308 |
.paket/paket.exe |
|
309 |
paket-files/ |
|
310 |
|
|
311 |
# FAKE - F# Make |
|
312 |
.fake/ |
|
313 |
|
|
314 |
# CodeRush personal settings |
|
315 |
.cr/personal |
|
316 |
|
|
317 |
# Python Tools for Visual Studio (PTVS) |
|
318 |
__pycache__/ |
|
319 |
*.pyc |
|
320 |
|
|
321 |
# Cake - Uncomment if you are using it |
|
322 |
# tools/** |
|
323 |
# !tools/packages.config |
|
324 |
|
|
325 |
# Tabs Studio |
|
326 |
*.tss |
|
327 |
|
|
328 |
# Telerik's JustMock configuration file |
|
329 |
*.jmconfig |
|
330 |
|
|
331 |
# BizTalk build output |
|
332 |
*.btp.cs |
|
333 |
*.btm.cs |
|
334 |
*.odx.cs |
|
335 |
*.xsd.cs |
|
336 |
|
|
337 |
# OpenCover UI analysis results |
|
338 |
OpenCover/ |
|
339 |
|
|
340 |
# Azure Stream Analytics local run output |
|
341 |
ASALocalRun/ |
|
342 |
|
|
343 |
# MSBuild Binary and Structured Log |
|
344 |
*.binlog |
|
345 |
|
|
346 |
# NVidia Nsight GPU debugger configuration file |
|
347 |
*.nvuser |
|
348 |
|
|
349 |
# MFractors (Xamarin productivity tool) working folder |
|
350 |
.mfractor/ |
|
351 |
|
|
352 |
# Local History for Visual Studio |
|
353 |
.localhistory/ |
|
354 |
|
|
355 |
# BeatPulse healthcheck temp database |
|
356 |
healthchecksdb |
|
357 |
|
|
358 |
# Backup folder for Package Reference Convert tool in Visual Studio 2017 |
|
359 |
MigrationBackup/ |
|
360 |
|
|
361 |
# Ionide (cross platform F# VS Code tools) working folder |
|
362 |
.ionide/ |
|
363 |
|
|
364 |
# Fody - auto-generated XML schema |
|
365 |
FodyWeavers.xsd |
|
366 |
|
|
367 |
### VisualStudio Patch ### |
|
368 |
# Additional files built by Visual Studio |
|
369 |
*.tlog |
|
370 |
|
|
371 |
# End of https://www.toptal.com/developers/gitignore/api/visualstudio |
TextureEditing/MapEditor.cs | ||
---|---|---|
1 |
using System; |
|
2 |
using System.Collections.Generic; |
|
3 |
using System.Drawing; |
|
4 |
using System.Drawing.Imaging; |
|
5 |
using System.IO; |
|
6 |
using System.Text; |
|
7 |
|
|
8 |
namespace TextureEditing |
|
9 |
{ |
|
10 |
/// <summary> |
|
11 |
/// Edits input pngs |
|
12 |
/// </summary> |
|
13 |
class MapEditor |
|
14 |
{ |
|
15 |
/// <summary> Path to data </summary> |
|
16 |
string dataPath; |
|
17 |
/// <summary> Path to output folder </summary> |
|
18 |
string outPath; |
|
19 |
|
|
20 |
/// <summary> |
|
21 |
/// Constructor |
|
22 |
/// </summary> |
|
23 |
/// <param name="dataPath">Path to data</param> |
|
24 |
/// <param name="outPath">Path to output folder</param> |
|
25 |
public MapEditor(string dataPath, string outPath) |
|
26 |
{ |
|
27 |
this.dataPath = dataPath; |
|
28 |
this.outPath = outPath; |
|
29 |
} |
|
30 |
|
|
31 |
/// <summary> |
|
32 |
/// Crop all pngs from input data folder |
|
33 |
/// </summary> |
|
34 |
public void EditAllPngs() |
|
35 |
{ |
|
36 |
// does dataPath folder exist |
|
37 |
if (!Directory.Exists(dataPath)) |
|
38 |
{ |
|
39 |
Console.WriteLine("Path does not exist"); |
|
40 |
return; |
|
41 |
} |
|
42 |
|
|
43 |
List<PngEdited> cropped = new List<PngEdited>(); |
|
44 |
|
|
45 |
// for all files |
|
46 |
string[] files = Directory.GetFiles(dataPath); |
|
47 |
foreach (string f in files) |
|
48 |
{ |
|
49 |
Console.WriteLine("Processing file " + f); |
|
50 |
Bitmap img = new Bitmap(f); |
|
51 |
var newpng = Crop(img); |
|
52 |
newpng.name = Path.GetFileName(f); |
|
53 |
PositionInOriginal(img, newpng); |
|
54 |
PositionOfCentroid(newpng); |
|
55 |
cropped.Add(newpng); |
|
56 |
|
|
57 |
newpng.Save(outPath + "/" + newpng.name); |
|
58 |
} |
|
59 |
SaveTxt(cropped); |
|
60 |
|
|
61 |
/* |
|
62 |
int c = 0; |
|
63 |
foreach (PngEdited p in cropped) |
|
64 |
{ |
|
65 |
c++; |
|
66 |
TestImage(p, c); |
|
67 |
} |
|
68 |
*/ |
|
69 |
} |
|
70 |
|
|
71 |
/// <summary> |
|
72 |
/// Testing method |
|
73 |
/// Prints out cropped image positioned back to original map and image with visible centroid |
|
74 |
/// </summary> |
|
75 |
/// <param name="pngEdited">Output image</param> |
|
76 |
/// <param name="i">Number of image</param> |
|
77 |
private void TestImage(PngEdited pngEdited, int i) |
|
78 |
{ |
|
79 |
Bitmap png = new Bitmap("./bory-buildings.png"); |
|
80 |
Bitmap newpng = pngEdited.png; |
|
81 |
|
|
82 |
Bitmap centroid = new Bitmap(20, 20); |
|
83 |
for (int h = 0; h < centroid.Height; h++) |
|
84 |
for (int w = 0; w < centroid.Width; w++) |
|
85 |
centroid.SetPixel(w, h, Color.Red); |
|
86 |
|
|
87 |
|
|
88 |
int xPos = (int)((newpng.Width / 100.0f) * pngEdited.xCentr) - 10; |
|
89 |
int yPos = (int)((newpng.Height / 100.0f) * (100 - pngEdited.yCentr)) - 10; |
|
90 |
|
|
91 |
Bitmap centroidTest = new Bitmap(newpng.Width, newpng.Height); |
|
92 |
using (Graphics g = Graphics.FromImage(centroidTest)) |
|
93 |
{ |
|
94 |
g.DrawImage(newpng, new Rectangle(0, 0, newpng.Width, newpng.Height), new Rectangle(0, 0, newpng.Width, newpng.Height), GraphicsUnit.Pixel); |
|
95 |
g.DrawImage(centroid, new Rectangle(xPos, yPos, 20, 20), new Rectangle(0, 0, centroidTest.Width, centroidTest.Height), GraphicsUnit.Pixel); |
|
96 |
|
|
97 |
centroidTest.Save($"testCentroidOut{i}.png", ImageFormat.Png); |
|
98 |
} |
|
99 |
|
|
100 |
for (int h = 0; h < newpng.Height; h++) |
|
101 |
for (int w = 0; w < newpng.Width; w++) |
|
102 |
{ |
|
103 |
if (newpng.GetPixel(w, h).A != 0) |
|
104 |
{ |
|
105 |
newpng.SetPixel(w, h, Color.Red); |
|
106 |
} |
|
107 |
} |
|
108 |
|
|
109 |
xPos = (int) ((png.Width / 100.0f) * pngEdited.xPerc); |
|
110 |
yPos = (int)((png.Height / 100.0f) * (100-pngEdited.yPerc)) - newpng.Height; |
|
111 |
|
|
112 |
using (Graphics g = Graphics.FromImage(png)) |
|
113 |
{ |
|
114 |
g.DrawImage(newpng, new Rectangle(xPos, yPos, newpng.Width, newpng.Height), new Rectangle(0, 0, newpng.Width, newpng.Height), GraphicsUnit.Pixel); |
|
115 |
png.Save($"testOut{i}.png", ImageFormat.Png); |
|
116 |
} |
|
117 |
} |
|
118 |
|
|
119 |
/// <summary> |
|
120 |
/// Compute the position of centroid. Coordinates are computed in % from bottom left corner of cropped png |
|
121 |
/// </summary> |
|
122 |
/// <param name="newpng">Output png in instance PngEdited</param> |
|
123 |
private void PositionOfCentroid(PngEdited newpng) |
|
124 |
{ |
|
125 |
// from all non transparent pixels |
|
126 |
int coordY = 0, coordX = 0; |
|
127 |
int count = 0; |
|
128 |
for (int h = 0; h < newpng.png.Height; h++) |
|
129 |
for (int w = 0; w < newpng.png.Width; w++) |
|
130 |
{ |
|
131 |
if (newpng.png.GetPixel(w, h).A != 0 ) |
|
132 |
{ |
|
133 |
count++; |
|
134 |
coordY += h; |
|
135 |
coordX += w; |
|
136 |
} |
|
137 |
} |
|
138 |
|
|
139 |
// coordinates |
|
140 |
newpng.xCentr = coordX / count; |
|
141 |
newpng.yCentr = coordY / count; |
|
142 |
|
|
143 |
// to % |
|
144 |
float onePercX = newpng.png.Width / 100.0f; |
|
145 |
float percX = newpng.xCentr / onePercX; |
|
146 |
newpng.xCentr = percX; |
|
147 |
|
|
148 |
float onePercY = newpng.png.Height / 100.0f; |
|
149 |
float percY = 100 - (newpng.yCentr / onePercY); |
|
150 |
newpng.yCentr = percY; |
|
151 |
} |
|
152 |
|
|
153 |
/// <summary> |
|
154 |
/// Find the position of cropped image in original. Coordinates of bottom left corner are computed in % from bottom left corner of original |
|
155 |
/// </summary> |
|
156 |
/// <param name="img">Original</param> |
|
157 |
/// <param name="newpng">New image</param> |
|
158 |
private void PositionInOriginal(Bitmap img, PngEdited newpng) |
|
159 |
{ |
|
160 |
// left bottom corner |
|
161 |
int xLeft = newpng.xStart; |
|
162 |
int yLeft = newpng.yEnd; |
|
163 |
|
|
164 |
// compute percentages |
|
165 |
float onePercX = img.Width / 100.0f; |
|
166 |
float percX = xLeft / onePercX; |
|
167 |
newpng.xPerc = percX; |
|
168 |
|
|
169 |
float onePercY = img.Height / 100.0f; |
|
170 |
float percY = 100 - (yLeft / onePercY); |
|
171 |
newpng.yPerc = percY; |
|
172 |
} |
|
173 |
|
|
174 |
/// <summary> |
|
175 |
/// Save information about output files as csv |
|
176 |
/// [name];[x coordinate of bottom left corner];[y coordinate of bottom left corner];[x coordinate of centroid];[y coordinate of centroid] |
|
177 |
/// Coordinates of bottom left corner are computed in % from bottom left corner of original, coordinates of centroid are computed in % from bottom left corner of output png |
|
178 |
/// </summary> |
|
179 |
/// <param name="cropped"></param> |
|
180 |
private void SaveTxt(List<PngEdited> cropped) |
|
181 |
{ |
|
182 |
string res = ""; |
|
183 |
|
|
184 |
foreach (PngEdited png in cropped) |
|
185 |
res += $"{png.name};{png.xPerc};{png.yPerc};{png.xCentr};{png.yCentr}\n"; |
|
186 |
|
|
187 |
File.WriteAllBytes(outPath + "/output.csv", Encoding.ASCII.GetBytes(res)); |
|
188 |
} |
|
189 |
|
|
190 |
/// <summary> |
|
191 |
/// Crop image so it does not contain any transparent padding |
|
192 |
/// </summary> |
|
193 |
/// <param name="img">Original image</param> |
|
194 |
/// <returns>Cropped image as PngEdited instance</returns> |
|
195 |
private PngEdited Crop(Bitmap img) |
|
196 |
{ |
|
197 |
PngEdited res = new PngEdited(); |
|
198 |
|
|
199 |
int xFrom = img.Width, xTo = 0; |
|
200 |
int yFrom = img.Height, yTo = 0; |
|
201 |
|
|
202 |
// find start + end of x and y |
|
203 |
for (int h = 0; h < img.Height; h++) |
|
204 |
for (int w = 0; w < img.Width; w++) |
|
205 |
{ |
|
206 |
if (img.GetPixel(w, h).A != 0 && xFrom > w) |
|
207 |
xFrom = w; |
|
208 |
|
|
209 |
if (img.GetPixel(w, h).A != 0 && xTo < w) |
|
210 |
xTo = w; |
|
211 |
|
|
212 |
if (img.GetPixel(w, h).A != 0 && yFrom > h) |
|
213 |
yFrom = h; |
|
214 |
|
|
215 |
if (img.GetPixel(w, h).A != 0 && yTo < h) |
|
216 |
yTo = h; |
|
217 |
} |
|
218 |
|
|
219 |
|
|
220 |
// crop |
|
221 |
Bitmap cropped = new Bitmap(xTo - xFrom + 1, yTo - yFrom + 1); |
|
222 |
using (Graphics g = Graphics.FromImage(cropped)) |
|
223 |
{ |
|
224 |
g.DrawImage(img, new Rectangle(0, 0, cropped.Width, cropped.Height), new Rectangle(xFrom, yFrom, cropped.Width, cropped.Height), GraphicsUnit.Pixel); |
|
225 |
res.png = cropped; |
|
226 |
} |
|
227 |
|
|
228 |
res.xStart = xFrom; |
|
229 |
res.xEnd = xTo; |
|
230 |
res.yStart = yFrom; |
|
231 |
res.yEnd = yTo; |
|
232 |
|
|
233 |
return res; |
|
234 |
} |
|
235 |
|
|
236 |
} |
|
237 |
} |
TextureEditing/PngEdited.cs | ||
---|---|---|
1 |
using System.Drawing; |
|
2 |
using System.Drawing.Imaging; |
|
3 |
|
|
4 |
namespace TextureEditing |
|
5 |
{ |
|
6 |
/// <summary> |
|
7 |
/// Output png carrier |
|
8 |
/// </summary> |
|
9 |
class PngEdited |
|
10 |
{ |
|
11 |
/// <summary> Name of png </summary> |
|
12 |
public string name; |
|
13 |
|
|
14 |
/// <summary> Image </summary> |
|
15 |
public Bitmap png; |
|
16 |
|
|
17 |
/// <summary> Coordinates of max and min x in original image </summary> |
|
18 |
public int xStart, xEnd; |
|
19 |
/// <summary> Coordinates of max and min y in original image </summary> |
|
20 |
public int yStart, yEnd; |
|
21 |
|
|
22 |
/// <summary> Coordinates of bottom left corner in % from bottom left corner of original </summary> |
|
23 |
public float xPerc, yPerc; |
|
24 |
/// <summary> Coordinates of centroid in % from bottom left corner of cropped image </summary> |
|
25 |
public float xCentr, yCentr; |
|
26 |
|
|
27 |
/// <summary> |
|
28 |
/// Save as png file |
|
29 |
/// </summary> |
|
30 |
/// <param name="outPath">Path to output file</param> |
|
31 |
internal void Save(string outPath) |
|
32 |
{ |
|
33 |
png.Save(outPath, ImageFormat.Png); |
|
34 |
} |
|
35 |
} |
|
36 |
} |
TextureEditing/Program.cs | ||
---|---|---|
1 |
using System; |
|
2 |
using System.Globalization; |
|
3 |
|
|
4 |
namespace TextureEditing |
|
5 |
{ |
|
6 |
/// <summary> |
|
7 |
/// Main class |
|
8 |
/// </summary> |
|
9 |
class Program |
|
10 |
{ |
|
11 |
/// <summary> |
|
12 |
/// Main method |
|
13 |
/// - needs one argument - path to folder with input files |
|
14 |
/// </summary> |
|
15 |
/// <param name="args">args</param> |
|
16 |
static void Main(string[] args) |
|
17 |
{ |
|
18 |
CultureInfo.CurrentCulture = new CultureInfo("en-US", false); |
|
19 |
|
|
20 |
if (args.Length < 1) |
|
21 |
{ |
|
22 |
Console.WriteLine("Insufficient arguments, input path to folder with data"); |
|
23 |
return; |
|
24 |
} |
|
25 |
|
|
26 |
string dataPath = args[0]; |
|
27 |
|
|
28 |
MapEditor me = new MapEditor(dataPath, "./output"); |
|
29 |
me.EditAllPngs(); |
|
30 |
|
|
31 |
Console.WriteLine("Done."); |
|
32 |
} |
|
33 |
} |
|
34 |
} |
TextureEditing/Properties/launchSettings.json | ||
---|---|---|
1 |
{ |
|
2 |
"profiles": { |
|
3 |
"TextureEditing": { |
|
4 |
"commandName": "Project", |
|
5 |
"commandLineArgs": "./data" |
|
6 |
} |
|
7 |
} |
|
8 |
} |
TextureEditing/TextureEditing.csproj | ||
---|---|---|
1 |
<Project Sdk="Microsoft.NET.Sdk"> |
|
2 |
|
|
3 |
<PropertyGroup> |
|
4 |
<OutputType>Exe</OutputType> |
|
5 |
<TargetFramework>net5.0</TargetFramework> |
|
6 |
</PropertyGroup> |
|
7 |
|
|
8 |
<ItemGroup> |
|
9 |
<PackageReference Include="System.Drawing.Common" Version="5.0.2" /> |
|
10 |
</ItemGroup> |
|
11 |
|
|
12 |
<ItemGroup> |
|
13 |
<None Update="data\CIV.png"> |
|
14 |
<CopyToOutputDirectory>Always</CopyToOutputDirectory> |
|
15 |
</None> |
|
16 |
<None Update="data\FAV.png"> |
|
17 |
<CopyToOutputDirectory>Always</CopyToOutputDirectory> |
|
18 |
</None> |
|
19 |
<None Update="data\FDU.png"> |
|
20 |
<CopyToOutputDirectory>Always</CopyToOutputDirectory> |
|
21 |
</None> |
|
22 |
<None Update="data\FEL.png"> |
|
23 |
<CopyToOutputDirectory>Always</CopyToOutputDirectory> |
|
24 |
</None> |
|
25 |
<None Update="data\FST+FEK.png"> |
|
26 |
<CopyToOutputDirectory>Always</CopyToOutputDirectory> |
|
27 |
</None> |
|
28 |
<None Update="data\LIB.png"> |
|
29 |
<CopyToOutputDirectory>Always</CopyToOutputDirectory> |
|
30 |
</None> |
|
31 |
<None Update="data\MENZA.png"> |
|
32 |
<CopyToOutputDirectory>Always</CopyToOutputDirectory> |
|
33 |
</None> |
|
34 |
<None Update="data\REK.png"> |
|
35 |
<CopyToOutputDirectory>Always</CopyToOutputDirectory> |
|
36 |
</None> |
|
37 |
</ItemGroup> |
|
38 |
|
|
39 |
</Project> |
TextureEditing/TextureEditing.sln | ||
---|---|---|
1 |
|
|
2 |
Microsoft Visual Studio Solution File, Format Version 12.00 |
|
3 |
# Visual Studio Version 16 |
|
4 |
VisualStudioVersion = 16.0.31105.61 |
|
5 |
MinimumVisualStudioVersion = 10.0.40219.1 |
|
6 |
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "TextureEditing", "TextureEditing.csproj", "{5DD75463-80DC-42AC-871C-2C5DF4F347CD}" |
|
7 |
EndProject |
|
8 |
Global |
|
9 |
GlobalSection(SolutionConfigurationPlatforms) = preSolution |
|
10 |
Debug|Any CPU = Debug|Any CPU |
|
11 |
Release|Any CPU = Release|Any CPU |
|
12 |
EndGlobalSection |
|
13 |
GlobalSection(ProjectConfigurationPlatforms) = postSolution |
|
14 |
{5DD75463-80DC-42AC-871C-2C5DF4F347CD}.Debug|Any CPU.ActiveCfg = Debug|Any CPU |
|
15 |
{5DD75463-80DC-42AC-871C-2C5DF4F347CD}.Debug|Any CPU.Build.0 = Debug|Any CPU |
|
16 |
{5DD75463-80DC-42AC-871C-2C5DF4F347CD}.Release|Any CPU.ActiveCfg = Release|Any CPU |
|
17 |
{5DD75463-80DC-42AC-871C-2C5DF4F347CD}.Release|Any CPU.Build.0 = Release|Any CPU |
|
18 |
EndGlobalSection |
|
19 |
GlobalSection(SolutionProperties) = preSolution |
|
20 |
HideSolutionNode = FALSE |
|
21 |
EndGlobalSection |
|
22 |
GlobalSection(ExtensibilityGlobals) = postSolution |
|
23 |
SolutionGuid = {34D2AE75-489A-43B1-9FB3-6649846B7046} |
|
24 |
EndGlobalSection |
|
25 |
EndGlobal |
Také k dispozici: Unified diff
re #8935 Program that can crop textures and outputs cropped versions + coordinates in original + coordinates of centroid in output image