array of images

creating a new image when i press a button

  • (3 Pages)
  • +
  • 1
  • 2
  • 3

33 Replies - 25078 Views - Last Post: 11 November 2008 - 08:58 AM Rate Topic: -----

#1 Sharkadder  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 39
  • Joined: 17-March 08

array of images

Post icon  Posted 31 October 2008 - 11:07 AM

Hi, i am after an array of images for when i press a button. I will not know how many images i need so i would need some sort of counter to add one and then create an image with that name if you get me.

Here is code that i have currently tried and it doesn't work:

                  int image = 1;
                    if (noteadd == 1)
                    {
                        image++;
                        Image[] image = new Image[image];
                        image = Image.FromFile("image.gif");
                        //Graphics g = e.Graphics;
                        if (image != null)
                        {
                            // Draw image using the DrawImage method
                            G.DrawImage(image, new Rectangle(noteslider.Location.X - 12, 10, image.Width, image.Height));
}

        private void label1_Click(object sender, EventArgs e)
        {
            //label1.Text = slidernoteX.ToString();
            noteadd = 1;
            label1.Text = noteadd.ToString();
            this.Refresh();
            noteadd = 0;
        }




Ok as you can see i have very badly created an image array, the array doesn't work and i haven't found much information on the internet about this (hence me posting here).

Basically here is the scenario which i am trying to achieve:

The user clicks on the label, when the user has pressed on the label an image is then created, this is at the x and y positions of a picturebox called noteslider. If i move the note slider i then want another image to be created at the notesliders position on screen. So far i have only been able to create 1 picture and when i move the noteslider the picture moves with it, instead of creating a second at that point.

So it goes click label--->create image at sliders position.

When i move the slider (this code is already implemented by myself), i then need to be able to press the label again, then a new image is created at the sliders x and y position on screen.

Thanks, if you are unsure then just ask, i can clarify what i am after if what i explained is a little hazey. I have been looking into this and am now stumped.

Mod Edit: Please use code tags when posting your code. Code tags are used like so => :code:

Thanks,
PsychoCoder :)

This post has been edited by PsychoCoder: 31 October 2008 - 11:40 AM


Is This A Good Question/Topic? 0
  • +

Replies To: array of images

#2 gbertoli3  Icon User is offline

  • DIC at Heart + Code
  • member icon

Reputation: 40
  • View blog
  • Posts: 1,162
  • Joined: 23-June 08

Re: array of images

Posted 31 October 2008 - 11:19 AM

There is a problem with your code. You have image declared twice. Once as an Integer and the other as an Image Array.

I think that you should change the Integer image to something like imgNum.

Also please use code tags when posting your code. :code:

Hope this helps

This post has been edited by gbertoli3: 31 October 2008 - 11:19 AM

Was This Post Helpful? 0
  • +
  • -

#3 Sharkadder  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 39
  • Joined: 17-March 08

Re: array of images

Posted 31 October 2008 - 12:38 PM

Well thanks for the comment, but i really don't know how to achieve what i am after, i have searched high and low on the internet and i find nothing, they are threads about arrays and images but they arn't about putting images into an array and then putting the image at a point on screen.

Sorry about the code, i forgot to put it in the code tags, it's been a while since i've been on here you see. I'm just unsure about array's with images in general, i know it can be done but i cannot get my head around how.

Anybody got a solution to this?

Thanks, i did change the variable names but that was never going to give me an answer to the problem. Nice tip though (y)
Was This Post Helpful? 0
  • +
  • -

#4 gbertoli3  Icon User is offline

  • DIC at Heart + Code
  • member icon

Reputation: 40
  • View blog
  • Posts: 1,162
  • Joined: 23-June 08

Re: array of images

Posted 31 October 2008 - 12:43 PM

If you want to put the images on a point in the Screen you can use the Graphics class.

Try this
            Image image = Image.FromFile("");
            Graphics graphics = Graphics.FromImage(image);
            graphics.DrawImage(image, new Point(0, 0));



Hope this helps
Was This Post Helpful? 0
  • +
  • -

#5 Sharkadder  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 39
  • Joined: 17-March 08

Re: array of images

Posted 31 October 2008 - 01:20 PM

Ok i know of the graphics class, basically i have been trying this and i have got images at a point on screen. What i am stuck with is getting more than 1 image on a position of the screen. I need to be able to create a new image using the same picture, i cannot create the same image twice you see as that name is already taken.

What i need is so when i click on the label it create a new image at the position of the slider, then when i press on the label again it will create another image at that position of the slider etc.

This post has been edited by Sharkadder: 31 October 2008 - 01:22 PM

Was This Post Helpful? 0
  • +
  • -

#6 gbertoli3  Icon User is offline

  • DIC at Heart + Code
  • member icon

Reputation: 40
  • View blog
  • Posts: 1,162
  • Joined: 23-June 08

Re: array of images

Posted 31 October 2008 - 01:25 PM

I don't understand what this would be useful for.
Was This Post Helpful? 0
  • +
  • -

#7 Sharkadder  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 39
  • Joined: 17-March 08

Re: array of images

Posted 31 October 2008 - 01:39 PM

Ok i will explain what it is i am trying to do, then you can make a suggestion on what you think might be best.

Basically i am creating a midi editor, the user selects a note and then presses a button and it draws the note onto the score where the slider is. Obviously more than 1 of the same note can be displayed on the screen. So for example the user selects a full note, they then press the button (in my case the label), then it adds the picture for that note where the slider is. The user can then move the slider(that code is already setup), then when they press the label again it will draw the same image picture at that new position on screen but with the old one remaining where it was.

Is it clearer now? Sorry if my explanation's arn't clear enough for you.

Thanks, hope you can think of a solution to help me now

This post has been edited by Sharkadder: 31 October 2008 - 01:40 PM

Was This Post Helpful? 0
  • +
  • -

#8 gbertoli3  Icon User is offline

  • DIC at Heart + Code
  • member icon

Reputation: 40
  • View blog
  • Posts: 1,162
  • Joined: 23-June 08

Re: array of images

Posted 31 October 2008 - 01:45 PM

The only thing I can think of would be a second Graphics class.

Just declare Graphics2, 3, 4, etc until you don't need any more notes.

Hope this helps

This post has been edited by gbertoli3: 31 October 2008 - 01:46 PM

Was This Post Helpful? 0
  • +
  • -

#9 Sharkadder  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 39
  • Joined: 17-March 08

Re: array of images

Posted 01 November 2008 - 06:31 AM

wouldn't that be a bit bulky? Surely theres a way to create a new image using a previous images picture. If i keep creating graphics classes all the time, what is going to happen when i have say 50 whole notes within the score? It is going to be mental.

They has to be an easier way, any suggestions people?
Was This Post Helpful? 0
  • +
  • -

#10 gbertoli3  Icon User is offline

  • DIC at Heart + Code
  • member icon

Reputation: 40
  • View blog
  • Posts: 1,162
  • Joined: 23-June 08

Re: array of images

Posted 01 November 2008 - 09:09 AM

You don't have to have 50 Graphics classes, but you said earlier that it was not working with only one Graphics class.
Was This Post Helpful? 0
  • +
  • -

#11 Sharkadder  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 39
  • Joined: 17-March 08

Re: array of images

Posted 01 November 2008 - 09:43 AM

Well i'm not sure, i have tried all sorts of code (as you can see). Could you by any chance test this out for me and upload some code that does work?

All i want is to assign an image from file to be drawn on screen, then when i click a button it draws another image at a position on the screen but leaving the previous image where it is.

I guess you could tell it to draw a new image at 10 pixels to the right every time you press a button or something for testing purposes. The closest i got was it to move the picture where the sliders position is, i have not figured out how to create more than 1 image with the same image from file at runtime.

I tried creating a new graphics but at runtime it won't do it as i need a name, if i try adding a counter to the graphics name everytime i click on the label, it won't let me do that. So i am a bit stumped at the moment

Thanks, but it really does bug you when you keep trying code and nothing seems to work.

This post has been edited by Sharkadder: 01 November 2008 - 09:45 AM

Was This Post Helpful? 0
  • +
  • -

#12 gbertoli3  Icon User is offline

  • DIC at Heart + Code
  • member icon

Reputation: 40
  • View blog
  • Posts: 1,162
  • Joined: 23-June 08

Re: array of images

Posted 01 November 2008 - 09:58 AM

Maybe something like this will work. Change the "sharp" and "sharp.png" to the actual music note and the location of the music note.

        public void DrawNote(String Note)
        {
            if (Note.ToLower() == "sharp")
            {
                Image image = Image.FromFile("sharp.png");
                Graphics graphics = Graphics.FromImage(image);
                graphics.DrawImage(image, new Point(0, 0));
            }
        }



Hope this helps
Was This Post Helpful? 0
  • +
  • -

#13 Sharkadder  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 39
  • Joined: 17-March 08

Re: array of images

Posted 01 November 2008 - 11:09 AM

Well i've tried calling the event but i get errors, "a graphics object cannot be created from an image that has an indexed pixel format"

Here is the code i have been trying, it's probably wrong but here goes:

	   public void DrawNote(String Note)  
		{  
			if (Note.ToLower() == "semibreve")
			{  
				Image image = Image.FromFile("semibreve.gif");  
				Graphics graphics = Graphics.FromImage(image);  
				graphics.DrawImage(image, new Point(20, 20));  
			}  
		} 

	   private void label1_Click(object sender, EventArgs e)
		{
			Note = "semibreve";
			DrawNote(Note);
			
		}



Any idea what is wrong?

This post has been edited by Sharkadder: 01 November 2008 - 11:11 AM

Was This Post Helpful? 0
  • +
  • -

#14 gbertoli3  Icon User is offline

  • DIC at Heart + Code
  • member icon

Reputation: 40
  • View blog
  • Posts: 1,162
  • Joined: 23-June 08

Re: array of images

Posted 01 November 2008 - 11:12 AM

Where(What Line) are you getting the error on?

Edit:

Quote

Note = "semibreve";

Did you Declare Note as a String somewhere in your code?

This post has been edited by gbertoli3: 01 November 2008 - 11:23 AM

Was This Post Helpful? 0
  • +
  • -

#15 Sharkadder  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 39
  • Joined: 17-March 08

Re: array of images

Posted 01 November 2008 - 11:34 AM

i get the error on this line:
				Graphics graphics = Graphics.FromImage(image); 



I thought the idea was that Note could be a string, so if i supply Note with a string and the if statement is equal to that string, then it will do the drawing of the image. This is correct but i get the error i spoke of.

I'm not sure how i resolve that error.
Was This Post Helpful? 0
  • +
  • -

  • (3 Pages)
  • +
  • 1
  • 2
  • 3