Click here to Skip to main content
15,893,594 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
Hi,

I am new to C# so I don't really know what I am doing.

I am having trouble running a function/method in C# and wonder if anyone can help me. I want to resize a simple image loaded in from openFileDialog. All I want to do is run a function how do I do that?

At the moment I have got:

private void btnConvert_Click(object sender, EventArgs e)
     {
         Image MyImg = Image.FromFile(openedFile);
         Image MyImg2 = Image.FromFile(openedFile);
         ResizeImage(MyImg, MyImg2, 523, 523, false);

     }


C#
public void ResizeImage(string OriginalFile, string NewFile, int NewWidth, int MaxHeight, bool OnlyResizeIfWider)
        {
//Code to execute
}


But for some reason I keep getting an error with the line:

ResizeImage(MyImg, MyImg2, 523, 523, false);

Which is to run the function/method. It comes up with the error "The best overload method match for 'form1.ResizeImage(String, String, Int, Int, Bool)' has some invalid arguments.
Posted
Updated 25-Jul-11 1:27am
v2

That usually means that one of your parameters is of the wrong type. It looks like MyImg and MyImg2 are Image types, and your method is expecting them to be a string.
 
Share this answer
 
v3
Comments
Willtwinny 25-Jul-11 7:38am    
I can't believe I am so stupid.
Thank-You, I kept thinking that it was returning a string (OpenFileDialog), when infact like you said I inserting it into a picture and then trying to pass that off as a string, instead of just passing it off as a string anyway.

Thank-You.
Your method signature is asking for 5 parameters the first 2 of which should be in the form of strings (presumably the path tot he old and new file). However, when you call it in btnConvert_Click you are passing Image objects as the first 2 parameters when, in fact, you should be passing the path as a string.
 
Share this answer
 
You can always check what are you receiving in MyImg, MyImg2 by debugging and by judging your error message: in this line

ResizeImage(MyImg, MyImg2, 523, 523, false); make sure

MyImg, and MyImg2 are of string type.

hope it helps :)

for further queries comment here!!
 
Share this answer
 
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900