Graphics在子窗体中加载图片
我想做一个图片处理软件,怎么在子窗体中打开图片?我想用Graphics画图,下面是我写的但是总是调试通了,但是加载不了图片,请各位高手指点!
Bitmap image_open;
Graphics graphicsObject;
double ZoomLevel = 1;
private void OpenFile(object sender, EventArgs e)
{
OpenFileDialog openFileDialog = new OpenFileDialog();
openFileDialog.InitialDirectory = Environment.GetFolderPath(Environment.SpecialFolder.Personal);
openFileDialog.Filter = "JPEG文件 (*.JPG)|*.JPG|位图文件 (*.BMP)|*.BMP|GIF文件 (*.GIF)|*.GIF|所有文件 (*.*)|*.*";
if (openFileDialog.ShowDialog(this) == DialogResult.OK)
{
string FileName = openFileDialog.FileName;
image_open = new Bitmap(openFileDialog.FileName);
Form childForm = new Form();
childForm.MdiParent = this;
childForm.Text = "图片" + childFormNumber++;
graphicsObject.Clear(childForm.BackColor);
graphicsObject.DrawImage(image_open, 121, 25, (int)(image_open.Width * ZoomLevel), (int)(image_open.Height * ZoomLevel));
childForm.Show();
// TODO: 在此处添加打开文件的代码。
}
} --------------------编程问答-------------------- 如下的语句改一下:
graphicsObject.Clear(childForm.BackColor);
graphicsObject.DrawImage(image_open, 121, 25, (int)(image_open.Width * ZoomLevel), (int)(image_open.Height * ZoomLevel));
childForm.Show();
-----------------
childForm.BackgroundImage=image_open;
1:没有见你正确的初始化graphicsObject对象;
2:既是你正确的初始化graphicsObject,也不会显示到窗体上。因为这时没有显示出来。
--------------------编程问答-------------------- 打开函数里只保存图片文件名,
Invalidate();
在child_OnPaint
里面画图、
--------------------编程问答-------------------- 一楼答案我早就知道,还是谢谢了!我还是想用Graphics方法应用这个功能
补充:.NET技术 , C#