done
This commit is contained in:
parent
ae5aa7fffb
commit
c4b53b7926
45
Program.cs
45
Program.cs
|
|
@ -15,6 +15,8 @@ namespace task_78
|
|||
return;
|
||||
|
||||
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();
|
||||
}
|
||||
|
||||
|
|
@ -50,6 +52,49 @@ namespace task_78
|
|||
bmp.Save(path);
|
||||
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 {
|
||||
|
|
|
|||
|
|
@ -45,7 +45,6 @@
|
|||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<Compile Include="PgmCreator.cs" />
|
||||
<Compile Include="PgmCreatorDemo.cs" />
|
||||
<Compile Include="Program.cs" />
|
||||
<Compile Include="Properties\AssemblyInfo.cs" />
|
||||
</ItemGroup>
|
||||
|
|
@ -55,6 +54,11 @@
|
|||
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
|
||||
</None>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<Content Include="test.png">
|
||||
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
|
||||
</Content>
|
||||
</ItemGroup>
|
||||
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
|
||||
<!-- 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.
|
||||
|
|
|
|||
Loading…
Reference in New Issue