0

Hi Guys,

I need to hand in a project tomorrow morning and its almost 6pm here so I need help as soon as possible.

I am trying to get the picture images from the Resource folder because I imported them to the Resource folder but cannot seem to retrieve them.

My code looks like this to retrieve them:

try
            {
                System.Reflection.Assembly thisExe;
                thisExe = System.Reflection.Assembly.GetExecutingAssembly();
                System.IO.Stream file = thisExe.GetManifestResourceStream(c.Image);
                pic.Image = Image.FromStream(file);

            }
            catch (Exception exc)
            {
                MessageBox.Show(exc.Message);
            }

Is that correct or how else can I get them from there? I need to put them in a Picture Box.

I get the following exception when trying to retrieve them from the Resource folder:

"Value of 'null' is not valid for 'stream'"

Any help please, its really urgent.

Thanks
Wesley

2
Contributors
4
Replies
5
Views
7 Years
Discussion Span
Last Post by ddanbe
0

Please stop using the word urgent, it is probably just your own fault...
But as I in a very good mood today, I will give you a tip. As a return I expect from you that if you have any problem in the future, it is not an URGENT one. Deal?
Try : myImage = Properties.Resources.ImageName;

Edited by ddanbe: n/a

0

Sorry about that, just had a really bad couple of days with this project so I am a bit frustrated, wont happen again I promise.

Do I delete everything and just put what you put of do I insert it somewhere in between?

Thanks

0

I think there is going to be a problem because I am trying to not only select one picture to put into the picture box, it needs to be quite a few that will be displayed randomly. Added the whole method so you can see more clearly:

// Adding a new card to the table
        private void NewCardOnTable(bool player, card c)
        {
            PictureBox pic = new PictureBox();
            try
            {
                System.Reflection.Assembly thisExe;
                thisExe = System.Reflection.Assembly.GetExecutingAssembly();
                System.IO.Stream file = thisExe.GetManifestResourceStream(c.Image);
                pic.Image = Image.FromStream(file);

            }
            catch (Exception exc)
            {
                MessageBox.Show(exc.Message);
            }


            if (player)
            {
                // Dealing to the dealer
                pic.Width = 104;
                pic.Height = 135;
                pic.Top = 364;
                pic.Left = 328 + (110 * totalCardsOnDealersSide++);
            }
            else
            {
                // Dealing to the player
                pic.Width = 104;
                pic.Height = 135;
                pic.Top = 364;
                pic.Left = 328 + (110 * totalCardsOnPlayersSide++);

            }

            pic.SizeMode = PictureBoxSizeMode.StretchImage;
            // Adding the picture to the picture boc.
            Controls.Add(pic);

            if (!thatsTheHoleCard)
                pictureBoxes.Add(pic);
            else
            {
                holeCardBox = pic;
                thatsTheHoleCard = false;
            }
        }

It needs to just display 4 cards, 2 for the dealer and 2 for the player.
Its for a blackjack game and in the Resources folder, there are 52 images but only need to select 4 random ones.

0

Yes just delete Lines 6 to 9 and change line 10 in:
pic.Image = Properties.Resources.ImageName;
ImageName being the name of the Resource of your pict in the resource file of your project.

Edited by ddanbe: n/a

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.