Resources.getbitmap doesn't exist!

Hello I’m trying to display an image on my TE35 display but when I write Resources.getbitmap it seems that the instruction doesn’t exist !

Somebody to help me ?

Thank you

Welcome to the forum!

  1. Method names are case sensitive.
  2. Resources related methods are generated by VS when you add resources in designer. If you just copied some code from somewhere make sure to add the resource first so the VS will add required code to the Resources class.

I’ve added a jpeg in ressources but visual studio says that resources doesn’t contain the definition for getbitmap.

            Bitmap logo = Resources.GetBitmap(Resources.logo);
            display_TE35.SimpleGraphics.DisplayImage(logo, 0, 0);

Open resources.cs and check what is there.

namespace GadgeteerApp1
{
    
    internal partial class Resources
    {
        private static System.Resources.ResourceManager manager;
        internal static System.Resources.ResourceManager ResourceManager
        {
            get
            {
                if ((Resources.manager == null))
                {
                    Resources.manager = new System.Resources.ResourceManager("GadgeteerApp1.Resources", typeof(Resources).Assembly);
                }
                return Resources.manager;
            }
        }
        internal static Microsoft.SPOT.Font GetFont(Resources.FontResources id)
        {
            return ((Microsoft.SPOT.Font)(Microsoft.SPOT.ResourceUtility.GetObject(ResourceManager, id)));
        }
        [System.SerializableAttribute()]
        internal enum FontResources : short
        {
            small = 13070,
            NinaB = 18060,
        }
    }
}

It’s not visible in intellisense until you add an image resource, save and close your project, open again and it’s there.

Try removing jpeg file and adding it again. Try other image types. I have just added a .jpg file and my resources.cs has these lines:


        internal static Microsoft.SPOT.Bitmap GetBitmap(Resources.BitmapResources id)
        {
            return ((Microsoft.SPOT.Bitmap)(Microsoft.SPOT.ResourceUtility.GetObject(ResourceManager, id)));
        }
 
 [System.SerializableAttribute()]
        internal enum BitmapResources : short
        {
            avatar = 25468,
        }

Thank you Architect, I’ve added this code in the designer.cs because it was not generated automatically and I’ve succesfully display my logo replacing your “avatar” by my “logo” in the designer.cs.

Now when I add other jpegs it doesn’t create the code in the designer.cs so :

  • Is it normal ?
  • Do I have to add it manually for any images in the designer.cs ?

And an other newbie question is : What are the maximum weight and size for images ?

When I add another image the program stops and the output says :
#### Message:
#### System.Resources.ResourceManager::GetObjectFromId [IP: 004e] ####
#### Microsoft.SPOT.ResourceUtility::GetObject [IP: 0000] ####
#### GadgeteerApp1.Resources::GetBitmap [IP: 000b] ####
#### GadgeteerApp1.ClassAffichage::AffichagePageGraph [IP: 01d8] ####
#### GadgeteerApp1.ClassAffichage::Paint [IP: 00c7] ####
#### GadgeteerApp1.Program::RefreshAffich_Tick [IP: 0008] ####
#### Microsoft.SPOT.DispatcherTimer::FireTick [IP: 0010] ####
#### Microsoft.SPOT.Dispatcher::PushFrameImpl [IP: 0054] ####
#### Microsoft.SPOT.Dispatcher::PushFrame [IP: 001a] ####
#### Microsoft.SPOT.Dispatcher::Run [IP: 0006] ####
#### Gadgeteer.Program::Run [IP: 0020] ####
Une exception de première chance de type ‘System.ArgumentException’ s’est produite dans mscorlib.dll
Exception performing Timer operation

Visual studio should add it for you. Try a new project from scratch and see if it does it. you don’t have to run it.

What VS are you using?

VS 2010

I’ve put all of my .cs in an new project and it still the same.

So I’ve made another project with the te35 only.

Here is my method to add the resource maybe that’s the problem !?

I right clic on Resources in “Solutions explorer” window and I add an existing element.

The designer cs doesn’t create the code for the getbitmap and the bitmap id…!!!

So… I’m a bit lost !

I see. You just adding jpg to the folder not to the resources using the designer.

  1. Double click Resources.resx
  2. Click “Add Resource” button where the arrow is and select “Add Existing File…”

Ok ! Thank you very much Architect…

I have the same problem and I added the jpg file with the designer but the problem is sill not solved I use vs2012, what can be wrong

@ Tati - Check this thread:

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

I want to load the image from resource to Image variable not Bitmap so I tried the code


        Bitmap saveBitmap = new Bitmap(Resources.GetBytes(Resources.BinaryResources.SaveImg), Bitmap.BitmapImageType.Jpeg);
        Bitmap skipBitmap = new Bitmap(Resources.GetBytes(Resources.BinaryResources.SkipImg), Bitmap.BitmapImageType.Jpeg);

        Image saveImage = new Image(saveBitmap) ;
        Image skipImage = new Image(skipBitmap);

and I got the error :

Error 1 A field initializer cannot reference the non-static field, method, or property ‘Biogas_Controller.Program.saveBitmap’

Error 2 A field initializer cannot reference the non-static field, method, or property ‘Biogas_Controller.Program.skipBitmap’

I found the error I modified the code to


        Image saveImage = new Image(new Bitmap(Resources.GetBytes(Resources.BinaryResources.SaveImg), Bitmap.BitmapImageType.Jpeg));
        Image skipImage = new Image(new Bitmap(Resources.GetBytes(Resources.BinaryResources.SkipImg), Bitmap.BitmapImageType.Jpeg));