Main Site Documentation

N18 Example... does not contain a definition for 'GetBitmap'


#1

Hi,

I have a Cobra II. I’ve just installed VS2012 and updated firmware etc. I’ve connected the N18 display and want to write a simple image to it, but I’m having problems with error messages, the first of which is

Error 1 ‘GadgeteerApp2.Resources’ does not contain a definition for ‘GetBitmap’

I’ve used the cut and pasted N18 example. I’ve added an image using the Resource.resx manager (I tried BMP, GIF anf JPG, drawn with Paint at a resolution of 128x160 which I believe matches the resolution of the N18).

Here is my full code. Can anyone see what I’m doing wrong?

Thanks, Philip

using System;
using System.Collections;
using System.Threading;
using Microsoft.SPOT;
using Microsoft.SPOT.Presentation;
using Microsoft.SPOT.Presentation.Controls;
using Microsoft.SPOT.Presentation.Media;
using Microsoft.SPOT.Presentation.Shapes;
using Microsoft.SPOT.Touch;
using Gadgeteer.Networking;
using GT = Gadgeteer;
using GTM = Gadgeteer.Modules;

namespace GadgeteerApp2
{
    public partial class Program
    {
        GTM.GHIElectronics.Display_N18 display_N18;
        // This method is run when the mainboard is powered up or reset.   
        void ProgramStarted()
        {
            /*******************************************************************************************
            Modules added in the Program.gadgeteer designer view are used by typing 
            their name followed by a period, e.g.  button.  or  camera.
            
            Many modules generate useful events. Type +=<tab><tab> to add a handler to an event, e.g.:
                button.ButtonPressed +=<tab><tab>
            
            If you want to do something periodically, use a GT.Timer and handle its Tick event, e.g.:
                GT.Timer timer = new GT.Timer(1000); // every second (1000ms)
                timer.Tick +=<tab><tab>
                timer.Start();
            *******************************************************************************************/
                        display_N18 = new GTM.GHIElectronics.Display_N18(6);
         
 
            // Usage example #1. Passing a Bitmap to the driver.
            Bitmap picture = Resources.GetBitmap(Resources.BitmapResources.Image1);
 
            display_N18.DrawBitmap(picture);
 
 
            // Usage example #2. Passing raw bitmap information to the driver, placing it at a certain location.
            byte[] newRender = new byte[50 * 50 * 2];
 
            Array.Copy(newRender, picture.GetBitmap(), newRender.Length);
 
            display_N18.DrawBitmapRawData(newRender, 0, 0, 50, 50);

            // Use Debug.Print to show messages in Visual Studio's "Output" window during debugging.
            Debug.Print("Program Started");
        }
    }
}

#2

Hi Andre.m,

No I didn’t copy the namespace text, it is called [quote]GadgeteerApp2 [/quote]and the image is named ‘Image1’ in resources.


#3

@ puresoft - VS doesn’t generate GetBitmap method when you add an image in 4.2. Use Bitmap constructor that accepts byte array and use GetBytes method from resource manager.

Edit:

Check this thread:

https://www.ghielectronics.com/community/forum/topic?id=14053

Somebody has been asking similar question.


#4

Hi Architect,

I read that ost and it seemed adding the image by the Resource.resx manger made it work for him, but I added the image via this resource manager method.

Could it be anything to do with me setting up the project through a Gadgeteer Application?

I added the Resource GTM.GHIElectronics.Display_N18 and then ran the program.


#5

I am not sure it did. It doesn’t for me.

I use GetBytes and binary resource approach as I have described earlier:


Bitmap bmp = new Bitmap(Resources.GetBytes(Resources.BinaryResources.Image1), Bitmap.BitmapImageType.Jpeg);

Edit: The issue is on the codeplex by the way:

https://www.ghielectronics.com/community/forum/topic?id=13244


#6

Hi Architect,

OK, so I have entered the line as you recommended and that error message disappears, so that is looking good. There are just two errors left, relating to the usage of the bitmap image, still based on the example code of page https://www.ghielectronics.com/docs/59/display-n18-module.

Here is my main code now. The lines with DrawBitmap and DrawBitmapRawData are throwing the errors. I suppose there is a way to format these commands like you just did the first one?

        void ProgramStarted()
        {

            display_N18 = new GTM.GHIElectronics.Display_N18(6);

            // Usage example #1. Passing a Bitmap to the driver.
            Bitmap picture = new Bitmap(Resources.GetBytes(Resources.BinaryResources.Image1), Bitmap.BitmapImageType.Jpeg);

            display_N18.DrawBitmap(picture);

            // Usage example #2. Passing raw bitmap information to the driver, placing it at a certain location.
            byte[] newRender = new byte[128 * 160 * 2];

            Array.Copy(newRender, picture.GetBitmap(), newRender.Length);

            display_N18.DrawBitmapRawData(newRender, 0, 0, 128, 160);

            // Use Debug.Print to show messages in Visual Studio's "Output" window during debugging.
            Debug.Print("Program Started");
        }

#7

Make sure you use the right image type. What kind of errors btw?


#8

Hi,

yes I’ve added a JPEG, it’s called Image1.jpg, created in MS Paint.

Sorry here is the errors that are left

Error 1 ‘Gadgeteer.Modules.GHIElectronics.Display_N18’ does not contain a definition for ‘DrawBitmap’ and no extension method ‘DrawBitmap’ accepting a first argument of type ‘Gadgeteer.Modules.GHIElectronics.Display_N18’ could be found (are you missing a using directive or an assembly reference?)

Error 2 ‘Gadgeteer.Modules.GHIElectronics.Display_N18’ does not contain a definition for ‘DrawBitmapRawData’ and no extension method ‘DrawBitmapRawData’ accepting a first argument of type ‘Gadgeteer.Modules.GHIElectronics.Display_N18’ could be found (are you missing a using directive or an assembly reference?)


#9

Are you using the module driver that comes with the SDK?


#10

I did a fresh install, as per the instructions of https://www.ghielectronics.com/support/netmf, for the VS2012 and the NETMF SDK 4.3 option (my project is targeting 4.2 in the Project settings). The COBRA II board autodetected a driver upon installation. Device manager reports ‘GHI NETMF Debug Interface’ as the USB driver. I also have the latest firmware on the board.

I created the Project using ‘VS2012 > New Project > Gadgeteer > Cobra II’.

I then added the Reference of GTI.GHIElectronics.Display_N18


#11

@ puresoft - The driver interface might have changed since that sample was written.

Use the Draw method instead of DrawBitmap and DrawRaw instead of DrawBitmapRawData.


#12

Yep, Chris is right

http://gadgeteer.codeplex.com/SourceControl/latest#Main/Modules/GHIElectronics/Display N18/Software/Display N18/Display_N18_42/Display_N18_42.cs

GHI needs to update that tutorial.


#13

OK, thanks guys, I now got it to work. Here is my working program for others. I will mention it on the feedback from for the original sample code page.

using System;
using System.Collections;
using System.Threading;
using Microsoft.SPOT;
using Microsoft.SPOT.Presentation;
using Microsoft.SPOT.Presentation.Controls;
using Microsoft.SPOT.Presentation.Media;
using Microsoft.SPOT.Presentation.Shapes;
using Microsoft.SPOT.Touch;

using Gadgeteer.Networking;
using GT = Gadgeteer;
using GTM = Gadgeteer.Modules;

namespace GadgeteerApp3
{
    public partial class Program
    {
        GTM.GHIElectronics.Display_N18 display_N18;
        // This method is run when the mainboard is powered up or reset.   
        void ProgramStarted()
        {
            display_N18 = new GTM.GHIElectronics.Display_N18(6);

            // Usage example #1. Passing a Bitmap to the driver.
            Bitmap picture = new Bitmap(Resources.GetBytes(Resources.BinaryResources.Image1), Bitmap.BitmapImageType.Jpeg);

            display_N18.Draw(picture);

            // Usage example #2. Passing raw bitmap information to the driver, placing it at a certain location.
            byte[] newRender = new byte[128 * 160 * 2];

            Array.Copy(newRender, picture.GetBitmap(), newRender.Length);

            display_N18.DrawRaw(newRender, 0, 0, 128, 160);

            // Use Debug.Print to show messages in Visual Studio's "Output" window during debugging.
            Debug.Print("Program Started");
        }
    }
}

#14

@ puresoft - thanks for asking your question in the forum. Questions answered here benefit the whole community!! Your follow-up using the feedback form on the documentation page is exactly the kind of usage we created it for – it’s not a request for tech support – it’s purely a comment/tag on the documentation which I will update. Glad you were successful.