Putting It All Together
We now have everything we need for the project, we just need to combine the “HelloWebServer” and “SketchPad” projects into one, and add some code to serve back the image on the screen rather than just text.
Load the project “WebMessenger” into Visual Studio.
Figure 4-10 shows the arrangements of the modules and as you would expect, we use a combination of all the modules from the “HelloWebServer” and “SketchPad” projects.
One of the first things to notice in the code is that there is a new “using” line at the top. This is to include a utility method that we need to use to convert the bitmap on the screen to a BMP file format:
using GHIElectronics.NETMF.System;
This method is to be found in an assembly that is not automatically included in the project. So, if you were starting your own project that needed to use this, you would have to refer to it from your project.
To do this, right-click over the project, select the option “Add Reference…”, then select “GHIElectronics.NETMF.System” from the list (see Figure 4-9).
Documentation for this method and other useful things can be found here: http://www.ghielectronics.com/downloads/NETMF/Library%20Documentation/
We define a WebEvent and call it sketch. The following shows the handler for
WebEventReceived for this WebEvent:
void sketch_WebEventReceived(string path, WebServer.HttpMethod method, Responder responder) { Bitmap bitmap = background.Bitmap; byte[] buff = new byte[bitmap.Width * bitmap.Height * 3 + 54]; Util.BitmapToBMPFile(bitmap.GetBitmap(), ...Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access