图像调整大小类Visual c#中的错误

Errors in the image resize class Visual c#
2021-09-15
  •  译文(汉语)
  •  原文(英语)

我试图在Microsoft Visual C#2010中制作一个益智游戏,当我尝试调整图像大小以适合组框时,出现以下错误:

error CS1502: The best overloaded method match for
'System.Drawing.Graphics.DrawImage(System.Drawing.Image,
System.Drawing.PointF)' has some invalid arguments

error CS1503: Argument 1: cannot convert from 'PuzzleImage.Form1' to
'System.Drawing.Image'

error CS1503: Argument 2: cannot convert from
'System.Drawing.Rectangle' to 'System.Drawing.PointF'

注意:错误位于代码的第二部分,位于私有Bitmap CreateBitmapImage(Form1 image)类中.

这是我的代码:

   OpenFileDialog openFileDialog = null;
    Form1 image;
    PictureBox picBoxWhole = null;

    private void buttonImageBrowse_Click(object sender, EventArgs e)
    {
        if (openFileDialog == null)
            openFileDialog = new OpenFileDialog();
        if (openFileDialog.ShowDialog() == System.Windows.Forms.DialogResult.OK)
        {

            System.Drawing.Image image = new Bitmap(openFileDialog.FileName); 
                if(picBoxWhole== null)
                {
                    picBoxWhole= new PictureBox();
                    picBoxWhole.Height = groupboxPuzzle.Height;
                    picBoxWhole.Width =groupboxPuzzle.Width;
                    groupboxPuzzle.Controls.Add(picBoxWhole);
                }
            picBoxWhole.Image= image;
        }
    }

    private Bitmap CreateBitmapImage(Form1 image)
    {
        Bitmap objBmpImage = new Bitmap(groupboxPuzzle.Width, groupboxPuzzle.Height);
        Graphics objGraphics = Graphics.FromImage(objBmpImage);
        objGraphics.Clear(Color.White);
        int x = groupboxPuzzle.Width;
        int y = groupboxPuzzle.Height;
        objGraphics.DrawImage(image,  new Rectangle(0,0, x, y));
        objGraphics.Flush();

        return objBmpImage;

    }

这是我当前正在关注的教程.也有人在77步处也谈到了一个错误.

速聊1:
好吧,阅读您的错误,您就会知道为什么会发生...
解决过程1

为什么要FormCreateBitmapImage()函数中传递参数?它在该教程中说接受Image类型参数.

private Bitmap CreateBitmapImage(Image image)
速聊1:
确实,但是图像具有相同的大小.无论如何,非常感谢.我将不得不再次执行本教程.
解决过程2

你需要改变

 Form1 image; to  Image image; //only if you need this :)

private Bitmap CreateBitmapImage(Form1 image) to private Bitmap CreateBitmapImage(Image image)

I'm trying to make a puzzle game in microsoft visual c# 2010 and when I try to resize the image to fit the groupbox I get these errors:

error CS1502: The best overloaded method match for
'System.Drawing.Graphics.DrawImage(System.Drawing.Image,
System.Drawing.PointF)' has some invalid arguments

error CS1503: Argument 1: cannot convert from 'PuzzleImage.Form1' to
'System.Drawing.Image'

error CS1503: Argument 2: cannot convert from
'System.Drawing.Rectangle' to 'System.Drawing.PointF'

NOTE: The errors are in the 2nd part of the code, int the private Bitmap CreateBitmapImage(Form1 image) class.

Here is my code:

   OpenFileDialog openFileDialog = null;
    Form1 image;
    PictureBox picBoxWhole = null;

    private void buttonImageBrowse_Click(object sender, EventArgs e)
    {
        if (openFileDialog == null)
            openFileDialog = new OpenFileDialog();
        if (openFileDialog.ShowDialog() == System.Windows.Forms.DialogResult.OK)
        {

            System.Drawing.Image image = new Bitmap(openFileDialog.FileName); 
                if(picBoxWhole== null)
                {
                    picBoxWhole= new PictureBox();
                    picBoxWhole.Height = groupboxPuzzle.Height;
                    picBoxWhole.Width =groupboxPuzzle.Width;
                    groupboxPuzzle.Controls.Add(picBoxWhole);
                }
            picBoxWhole.Image= image;
        }
    }

    private Bitmap CreateBitmapImage(Form1 image)
    {
        Bitmap objBmpImage = new Bitmap(groupboxPuzzle.Width, groupboxPuzzle.Height);
        Graphics objGraphics = Graphics.FromImage(objBmpImage);
        objGraphics.Clear(Color.White);
        int x = groupboxPuzzle.Width;
        int y = groupboxPuzzle.Height;
        objGraphics.DrawImage(image,  new Rectangle(0,0, x, y));
        objGraphics.Flush();

        return objBmpImage;

    }

And here is the tutorial that I am currently following. Also someone said something about an error at 77 step too.

Talk1:
Well, read your errors and you'll know why they are happening...
Solutions1

Why are you transferring a Form parameter in your CreateBitmapImage() function? It says in that tutorial to accept Image type parameter.

private Bitmap CreateBitmapImage(Image image)
Talk1:
Indeed, but the image has the same size. Anyway thank you very much. I'll have to do the tutorial again.
Solutions2

you need to change

 Form1 image; to  Image image; //only if you need this :)

and

private Bitmap CreateBitmapImage(Form1 image) to private Bitmap CreateBitmapImage(Image image)
转载于:https://stackoverflow.com/questions/15545209/errors-in-the-image-resize-class-visual-c-sharp

本人是.net程序员,因为英语不行,使用工具翻译,希望对有需要的人有所帮助
如果本文质量不好,还请谅解,毕竟这些操作还是比较费时的,英语较好的可以看原文

留言回复
我们只提供高质量资源,素材,源码,坚持 下了就能用 原则,让客户花了钱觉得值
上班时间 : 周一至周五9:00-17:30 期待您的加入