0

我正在尝试在 microsoft visual c# 2010 中制作益智游戏,当我尝试调整图像大小以适合 groupbox 时,出现以下错误:

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 步的错误。

4

2 回答 2

0

为什么要Form在函数中传输参数CreateBitmapImage()?它在那篇教程中说接受Image类型参数。

private Bitmap CreateBitmapImage(Image image)
于 2013-03-21T10:46:57.083 回答
0

你需要改变

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

private Bitmap CreateBitmapImage(Form1 image) to private Bitmap CreateBitmapImage(Image image)
于 2013-03-21T10:49:54.257 回答