Need help loading a resource file into a picturebox

This is a discussion on Need help loading a resource file into a picturebox within the C++ Programming forums, part of the General Programming Boards category; Hi All, I'm trying to figure out how to load the images from a resource file into a picturebox. I ...

  1. #1
    Registered User
    Join Date
    Apr 2011
    Posts
    40

    Need help loading a resource file into a picturebox

    Hi All,


    I'm trying to figure out how to load the images from a resource file into a picturebox. I have searched through on this forum, but most of them are for visual basic and other programming languages, but I can't figured it out for c++.

    I have added a picture into the Resources.resx file in the properties folder. I have also added an image called myimage1.png to the resources folder. I need your help because I don't know how I can get access to the Resources.res to load up the images and place the images in the picturebox when I click on the form button to change the images. Please can someone help?


    Anyone who can help me with this would be much appreicate.

    Thanks,
    Mark

  2. #2
    train spotter
    Join Date
    Aug 2001
    Location
    near a computer
    Posts
    3,859
    Look in the Windows section of these boards.

    Depends on what version of C++ and SDK you are using (pure WIN32, .NET and managed C++ ?).

    Did you add the image file to a folder or add the image as a resource?

    It could be as simple as

    MyPictureBox.Image = (Bitmap)new Bitmap(imagePath);

    or

    HBITMAP hImage = (HBITMAP) LoadImage(hInstance, MAKEINTRESOURCE(IDI_THE_IMAGE),IMAGE_BITMAP,0,0,LR _DEFAULTCOLOR);
    //where IDI_THE_IMAGE is the ID you gave the image when you aded it as a resource
    or
    HBITMAP hImage = (HBITMAP) LoadImage(hInstance, (LPCTSTR)"myimage1.png", IMAGE_BITMAP, 0, 0, LR_LOADFROMFILE | LR_DEFAULTSIZE); //not 100% that works with pngs

    MyPictureBox.Image = hImage;

    More details would make it easier to find your problem.
    "Man alone suffers so excruciatingly in the world that he was compelled to invent laughter."
    Friedrich Nietzsche

    "I spent a lot of my money on booze, birds and fast cars......the rest I squandered."
    George Best

    "If you are going through hell....keep going."
    Winston Churchill

  3. #3
    Registered User
    Join Date
    Apr 2011
    Posts
    40
    Well, I am using managed C++/CLI so how I can link up the image from the resource filename called myimages.resx and then load them into picturebox?

    As both code you have post isn't what I have asked for. I have asked for how I can link up the image from the resource filename and then load them into a picturebox, something like this:


    System::Resources::ResourceManager^ resources = gcnew System::Resources::ResourceManager("MyApplication. Form1", System::Reflection::Assembly::GetExecutingAssembly ());
    Label1->Image = cli::safe_cast<System:rawing::Image^>(resources->GetObject("images.jpg"));


    When I click on the button, none of them have been link up to the resource file and then load the images into picturebox.

    Please help!!!!

  4. #4
    Registered User
    Join Date
    Apr 2011
    Posts
    40
    anyone?

  5. #5
    train spotter
    Join Date
    Aug 2001
    Location
    near a computer
    Posts
    3,859
    Sorry I do not understand what you want to do.

    Do you want to click a button and have the image in the picture box change?

    Try explaining it again, step by step of what should happen and what actually happens.

    If possible post code. Then I can tell what 'level' of coder to aim my answer at.
    "Man alone suffers so excruciatingly in the world that he was compelled to invent laughter."
    Friedrich Nietzsche

    "I spent a lot of my money on booze, birds and fast cars......the rest I squandered."
    George Best

    "If you are going through hell....keep going."
    Winston Churchill

  6. #6
    Registered User
    Join Date
    Apr 2011
    Posts
    40
    yes novacain, I want to click a button and have the image in the picturebox change.

    I am using this code to change the image:

    Code:
        System::Resources::ResourceManager^ rmngr = _ 
        gcnew System::Resources::ResourceManager("myImages.Resources", _ 
        this->GetType()->Assembly)
        Label1->Image = safe_cast<Bitmap ^>(rmngr->GetObject("buttonblue"));

    Error: An unhandled exception of type 'System.Resources.MissingManifestResourceException ' occurred in mscorlib.dll

    Additional information: Could not find any resources appropriate for the specified culture or the neutral culture. Make sure "myImages.Resources.resources" was correctly embedded or linked into assembly "MyApplication" at compile time, or that all the satellite assemblies required are loadable and fully signed.



    I have stored the images in the myImages.resx, and the name of the resource are named correctly. I don't really understand what it suppose to mean and why I have got an error, please can you help?


    Thanks,
    Mark

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. C# and PictureBox not loading
    By martind1 in forum C# Programming
    Replies: 2
    Last Post: 02-02-2011, 09:47 AM
  2. Loading an image in from a resource file
    By starcatcher in forum C++ Programming
    Replies: 4
    Last Post: 04-15-2008, 07:44 AM
  3. Loading BITMAP Resource
    By FWGaming in forum C++ Programming
    Replies: 1
    Last Post: 07-19-2005, 01:07 PM
  4. Loading a resource file
    By Lariumentiko in forum Game Programming
    Replies: 2
    Last Post: 02-14-2003, 03:16 PM
  5. Loading Resource Bitmaps
    By Xterria in forum Windows Programming
    Replies: 10
    Last Post: 11-11-2001, 01:12 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21