Here's a cool demo you can try to make. I'll be using a 8x8 NeoPixel panel. The code shall draw a background image on the panel, and then overlay some text on it as well.
First, I created a bitmap file, 8 by 8 pixels. It looks like the following: (well... it is a really REALLY small file)
First, I created a bitmap file, 8 by 8 pixels. It looks like the following: (well... it is a really REALLY small file)
Here's a zoomed in version of the same file
I saved it as "examplebitmap.bmp".
In your C# project, use "add a new file" to add "MyResources.resx". Open "MyResources.resx" and use "add existing file" to add "examplebitmap.bmp". This is the fastest way to embed an image into your project.
(note: this takes up a lot of your precious flash memory! remember: the Netduino Plus 2 also has a microSD card slot you can use, or you can even download images from the network since it has built-in Ethernet)
(note: I have included JPEG and GIF decoding, but I haven't tried them out yet)
To use the resource, you can simply write
In your C# project, use "add a new file" to add "MyResources.resx". Open "MyResources.resx" and use "add existing file" to add "examplebitmap.bmp". This is the fastest way to embed an image into your project.
(note: this takes up a lot of your precious flash memory! remember: the Netduino Plus 2 also has a microSD card slot you can use, or you can even download images from the network since it has built-in Ethernet)
(note: I have included JPEG and GIF decoding, but I haven't tried them out yet)
To use the resource, you can simply write
Bitmap bm = MyResources.GetBitmap(MyResources.BitmapResources.examplebitmap);
There has been a bug report that Visual Studio 2012 does not process the bitmap resource properly. I know Visual Studio 2010 does work.
Next, we'll embed a font into the project so we can draw text.
We are using a 8 pixel tall panel so it makes sense to use a font specifically designed to be 8 pixels tall. I'm using one called "Apple ][" from http://www.dafont.com/apple.font. Download the .ttf file.
Use "Tiny Font Tool" from http://informatix.miloush.net/microframework/Utilities/TinyFontTool.aspx to generate a .tinyfnt file. I called mine "apple2.tinyfnt"
(note: the porting kit comes with another tool called "TFConvert.exe" to do the same thing but "Tiny Font Tool" is MUCH better, thank you Miloush!)
Open "MyResources.resx" and use "add existing file" to add "apple2.tinyfnt".
You can now use the font like so:
We are using a 8 pixel tall panel so it makes sense to use a font specifically designed to be 8 pixels tall. I'm using one called "Apple ][" from http://www.dafont.com/apple.font. Download the .ttf file.
Use "Tiny Font Tool" from http://informatix.miloush.net/microframework/Utilities/TinyFontTool.aspx to generate a .tinyfnt file. I called mine "apple2.tinyfnt"
(note: the porting kit comes with another tool called "TFConvert.exe" to do the same thing but "Tiny Font Tool" is MUCH better, thank you Miloush!)
Open "MyResources.resx" and use "add existing file" to add "apple2.tinyfnt".
You can now use the font like so:
Font f = MyResources.GetFont(MyResources.FontResources.apple2);
Make sure that in your project references, you've added "Microsoft.SPOT.Graphics"
Now back to our original goal: put some text on a bitmap, and show it on the NeoPixel panel.
using System; using System.Threading; using Microsoft.SPOT; using Microsoft.SPOT.Hardware; using SecretLabs.NETMF.Hardware; using SecretLabs.NETMF.Hardware.Netduino; using NeoPixel; using Microsoft.SPOT.Presentation.Media; namespace NeoPixelBitmapTextDemo { public class Program { public static void Main() { NeoPixelWriter w = new NeoPixelWriter(Pins.GPIO_PIN_D0); while (true) { foreach (char c in "ABCabc") { for (int i = -8; i < 8; i++) { Bitmap bm = MyResources.GetBitmap(MyResources.BitmapResources.examplebitmap); Font f = MyResources.GetFont(MyResources.FontResources.apple2); bm.DrawText("" + c, f, Color.White, 1, i); w.Write(bm, NeoPixelWriter.GridArrangment.LeftToRight_TopToBottom_Zigzag); Thread.Sleep(100); } } } } } }
(3MB GIF animation above, please wait for it to load)
Page last edited September 11, 2013
Text editor powered by tinymce.