diff --git a/sample/CairoPng.cs b/sample/CairoPng.cs new file mode 100644 index 000000000..f54e30d4f --- /dev/null +++ b/sample/CairoPng.cs @@ -0,0 +1,76 @@ +using System; +using System.Diagnostics; +using System.IO; +using Cairo; + +public class CairoPng +{ + public void CreatePng () + { + const int Width = 480; + const int Height = 160; + const int CheckSize = 10; + const int Spacing = 2; + + // Create an Image-based surface with data stored in ARGB32 format and a context, + // "using" is used here to ensure that they are Disposed once we are done + using (ImageSurface surface = new ImageSurface (Format.ARGB32, Width, Height)) + using (Context cr = new Cairo.Context (surface)) + { + // Start drawing a checkerboard + int i, j, xcount, ycount; + xcount = 0; + i = Spacing; + while (i < Width) { + j = Spacing; + ycount = xcount % 2; // start with even/odd depending on row + while (j < Height) { + if (ycount % 2 != 0) + cr.SetSourceRGB (1, 0, 0); + else + cr.SetSourceRGB (1, 1, 1); + // If we're outside the clip, this will do nothing. + cr.Rectangle (i, j, CheckSize, CheckSize); + cr.Fill (); + + j += CheckSize + Spacing; + ++ycount; + } + i += CheckSize + Spacing; + ++xcount; + } + + // Select a font to draw with + cr.SelectFontFace ("serif", FontSlant.Normal, FontWeight.Bold); + cr.SetFontSize (64.0); + + // Select a color (blue) + cr.SetSourceRGB (0, 0, 1); + + // Draw + cr.MoveTo (20, 100); + cr.ShowText ("Hello, World"); + + surface.WriteToPng ("test.png"); + } + } + + static void Main () + { + var app = new CairoPng (); + int iterations = 100; + + for (int loop = 0; loop < 10; loop++) { + Stopwatch stop_watch = new Stopwatch (); + stop_watch.Start (); + Console.Write ("Starting iterations, {0} bytes used...\t", Process.GetCurrentProcess().PrivateMemorySize64); + for (int i = 0; i < iterations; i++) { + app.CreatePng (); + } + stop_watch.Stop (); + Console.WriteLine ("Created {0} PNG files in {1}ms", iterations, stop_watch.ElapsedMilliseconds); + System.Threading.Thread.Sleep (1000); + } + } +} + diff --git a/sample/Makefile.am b/sample/Makefile.am index fd48ab858..eaba424e0 100755 --- a/sample/Makefile.am +++ b/sample/Makefile.am @@ -8,7 +8,7 @@ DOTNET_TARGETS= DOTNET_ASSEMBLY= endif -TARGETS = gtk-hello-world.exe async-sample.exe button.exe calendar.exe subclass.exe menu.exe treeviewdemo.exe managedtreeviewdemo.exe nodeviewdemo.exe treemodeldemo.exe actions.exe spawn.exe assistant.exe registerprop.exe gexceptiontest.exe native-instantiation.exe polarfixed.exe cairo-sample.exe scribble.exe testdnd.exe custom-cellrenderer.exe custom-widget.exe custom-scrollable.exe #scribble-xinput.exe $(DOTNET_TARGETS) +TARGETS = gtk-hello-world.exe async-sample.exe button.exe calendar.exe subclass.exe menu.exe treeviewdemo.exe managedtreeviewdemo.exe nodeviewdemo.exe treemodeldemo.exe actions.exe spawn.exe assistant.exe registerprop.exe gexceptiontest.exe native-instantiation.exe polarfixed.exe cairo-sample.exe scribble.exe testdnd.exe custom-cellrenderer.exe custom-widget.exe custom-scrollable.exe cairo-png.exe #scribble-xinput.exe $(DOTNET_TARGETS) DEBUGS = $(addsuffix .mdb, $(TARGETS)) @@ -103,6 +103,9 @@ registerprop.exe: $(srcdir)/PropertyRegistration.cs $(assemblies) gexceptiontest.exe: $(srcdir)/GExceptionTest.cs $(assemblies) $(CSC) $(CSFLAGS) -out:gexceptiontest.exe $(references) $(srcdir)/GExceptionTest.cs +cairo-png.exe: $(srcdir)/CairoPng.cs $(top_builddir)/cairo/cairo-sharp.dll + $(CSC) $(CSFLAGS) -out:cairo-png.exe -r:$(top_builddir)/cairo/cairo-sharp.dll $(srcdir)/CairoPng.cs + EXTRA_DIST = \ HelloWorld.cs \ Assistant.cs \ @@ -120,6 +123,7 @@ EXTRA_DIST = \ NativeInstantiationTest.cs \ NodeViewDemo.cs \ GExceptionTest.cs \ + CairoPng \ CairoSample.cs \ TestDnd.cs \ CustomCellRenderer.cs \ diff --git a/sample/sample.csproj b/sample/sample.csproj index a7450e77b..9afd33b14 100644 --- a/sample/sample.csproj +++ b/sample/sample.csproj @@ -108,6 +108,7 @@ +