Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
T
task_78
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
training
task_78
Commits
c4b53b79
Commit
c4b53b79
authored
Dec 15, 2016
by
David Neumaier
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
done
parent
ae5aa7ff
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
50 additions
and
1 deletion
+50
-1
Program.cs
Program.cs
+45
-0
task_78.csproj
task_78.csproj
+5
-1
test.png
test.png
+0
-0
No files found.
Program.cs
View file @
c4b53b79
...
@@ -15,6 +15,8 @@ namespace task_78
...
@@ -15,6 +15,8 @@ namespace task_78
return
;
return
;
writeFont
(
inFont
,
"font_print.bmp"
);
writeFont
(
inFont
,
"font_print.bmp"
);
Bitmap
testBmp
=
new
Bitmap
(
Image
.
FromFile
(
"test.png"
));
printToImage
(
testBmp
,
"test_print.bmp"
,
inFont
.
chars
.
ToArray
(),
128
,
64
);
Console
.
ReadLine
();
Console
.
ReadLine
();
}
}
...
@@ -50,6 +52,49 @@ namespace task_78
...
@@ -50,6 +52,49 @@ namespace task_78
bmp
.
Save
(
path
);
bmp
.
Save
(
path
);
Console
.
WriteLine
(
"Bitmap saved!"
);
Console
.
WriteLine
(
"Bitmap saved!"
);
}
}
/// <summary>
/// prints a single character on a bmp at a given destination
/// </summary>
/// <param name="bmp"></param>
/// <param name="c"></param>
/// <param name="x"></param>
/// <param name="y"></param>
/// <returns></returns>
private
static
Bitmap
printToImage
(
Bitmap
bmp
,
Font
.
Char
c
,
int
x
,
int
y
)
{
for
(
int
xx
=
0
;
xx
<
c
.
w
;
xx
++)
{
for
(
int
yy
=
0
;
yy
<
c
.
h
;
yy
++)
{
// Print every single pixel of given character
try
{
// respect the offset here, x = target location of character, xx = current iteration of character pixel.
int
code
=
c
.
data
[
xx
,
yy
];
if
(
code
!=
6
)
bmp
.
SetPixel
(
x
+
xx
,
y
+
yy
,
Color
.
FromArgb
(
255
,
code
,
code
,
code
));
}
catch
(
Exception
e
)
{
Console
.
WriteLine
(
e
.
Message
);
}
}
}
return
bmp
;
}
/// <summary>
/// Prints a given array of chars into a bitmap, then writes it to given destination file.
/// </summary>
/// <param name="source"></param>
/// <param name="destination"></param>
/// <param name="chars"></param>
/// <param name="x"></param>
/// <param name="y"></param>
public
static
void
printToImage
(
Bitmap
source
,
string
destination
,
Font
.
Char
[]
chars
,
int
x
,
int
y
)
{
int
shift
=
0
;
foreach
(
var
c
in
chars
)
{
source
=
printToImage
(
source
,
c
,
x
+
shift
,
y
);
shift
+=
c
.
w
+
1
;
}
source
.
Save
(
destination
);
Console
.
WriteLine
(
"printed a total of "
+
chars
.
Length
+
" characters to bmp, saved as "
+
destination
);
}
}
}
public
class
Font
{
public
class
Font
{
...
...
task_78.csproj
View file @
c4b53b79
...
@@ -45,7 +45,6 @@
...
@@ -45,7 +45,6 @@
</ItemGroup>
</ItemGroup>
<ItemGroup>
<ItemGroup>
<Compile Include="PgmCreator.cs" />
<Compile Include="PgmCreator.cs" />
<Compile Include="PgmCreatorDemo.cs" />
<Compile Include="Program.cs" />
<Compile Include="Program.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
</ItemGroup>
</ItemGroup>
...
@@ -55,6 +54,11 @@
...
@@ -55,6 +54,11 @@
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</None>
</None>
</ItemGroup>
</ItemGroup>
<ItemGroup>
<Content Include="test.png">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</Content>
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
Other similar extension points exist, see Microsoft.Common.targets.
Other similar extension points exist, see Microsoft.Common.targets.
...
...
test.png
0 → 100644
View file @
c4b53b79
This diff is collapsed.
Click to expand it.
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