帮助运行功能 [英] Help running a function

查看:45
本文介绍了帮助运行功能的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



我是C#的新手,所以我真的不知道自己在做什么.

我在C#中运行函数/方法时遇到麻烦,想知道是否有人可以帮助我.我想调整从openFileDialog加载的简单图像的大小.我要做的就是运行一个函数,该怎么做?

此刻我得到了:

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

     }



  public   void  ResizeImage(字符串 OriginalFile,字符串 NewFile, int  NewWidth, int  MaxHeight,布尔 OnlyResizeIfWider)
        {
// 要执行的代码
} 



但是由于某些原因,我在此行中始终遇到错误:

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

这是要运行的功能/方法.出现错误"form1.ResizeImage(String,String,Int,Int,Bool)的最佳重载方法匹配"具有一些无效的参数.

解决方案

这通常意味着您的参数之一是错误的类型,看起来MyImgMyImg2Image类型,并且您的方法期望它们是string.


您的方法签名要求输入5个参数,其中的前2个应该以字符串的形式出现(大概是新旧文件的路径).但是,当您在btnConvert_Click中调用它时,实际上,当您应该以字符串形式传递路径时,将图像对象作为前两个参数.


您始终可以通过调试和判断来检查MyImg, MyImg2中收到的内容您的错误消息:在此行

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

MyImg,MyImg2 string 类型.

希望对您有所帮助:)

有关更多查询,请在此处评论!!

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);

     }



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.

解决方案

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.


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.


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!!


这篇关于帮助运行功能的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆