I once tried to load svg images and bring them to the screen.
Worked better than I expected. Also here NuGet could help me so that my work on it was really minimal.
Here is the code for it.
namespace SVGTest
{
static class Program
{
/// <summary>
/// Der Haupteinstiegspunkt für die Anwendung.
/// </summary>
[STAThread]
static void Main()
{
Core.CreateWindow(AppInfo.WIN_TITLE, 640, 480, false);
if (!Core.InitAGK())
return;
Agk.SetVirtualResolution(640, 480);
Agk.SetClearColor(64, 64, 96);
AgkImage img = LoadImageSVG("media/Ghostscript_Tiger.svg", 480, 480);
AgkSprite spr = new AgkSprite(img);
spr.SetPosition((Agk.GetVirtualWidth() - img.Width) / 2, (Agk.GetVirtualHeight() - img.Height) / 2);
while (Core.LoopAGK())
{
spr.Draw();
Agk.Sync();
}
Core.CleanUp();
}
private static AgkImage LoadImageSVG(string Filename, uint Width, uint Height)
{
SvgDocument svgdoc = SvgDocument.Open("media/Ghostscript_Tiger.svg");
svgdoc.Width = Width;
svgdoc.Height = Height;
Bitmap bmp = svgdoc.Draw();
// Lock the bitmap's bits.
Rectangle rect = new Rectangle(0, 0, bmp.Width, bmp.Height);
System.Drawing.Imaging.BitmapData bmpData =
bmp.LockBits(rect, System.Drawing.Imaging.ImageLockMode.ReadWrite,
bmp.PixelFormat);
// Get the address of the first line.
IntPtr ptr = bmpData.Scan0;
// Declare an array to hold the bytes of the bitmap.
int bytes = Math.Abs(bmpData.Stride) * bmp.Height;
byte[] rgbValues = new byte[bytes];
// Copy the RGB values into the array.
System.Runtime.InteropServices.Marshal.Copy(ptr, rgbValues, 0, bytes);
// Unlock the bits.
bmp.UnlockBits(bmpData);
uint size = (uint)rgbValues.Length / sizeof(int);
int[] data = new int[size];
for (uint index = 0; index < size; index++)
{
uint bindex = index * sizeof(int);
data[index] = ((rgbValues[bindex + 3] << 24) | (rgbValues[bindex + 0] << 16) | (rgbValues[bindex + 1] << 8) | rgbValues[bindex + 2]);
}
return new AgkImage(Width, Height, data);
}
}
}
Share your knowledge. It\'s a way to achieve immortality.
(Tenzin Gyatso)