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)
Question
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.
Solution
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)
OTHER TIPS
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)