我程序如下,我想将我的picturebox1中的Graphics储存成image进行缩放
请教
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;namespace WindowsApplication1
{
public partial class Form1 : Form
{
bool a = false;
static int i = 0;
Point[] newpo = new Point[500];
Pen myPen = new Pen(Color.Black, 3);
Graphics myGraphics ;
public Bitmap m_bmpPic;
public Image img;
public Form1()
{
InitializeComponent();
} private void button1_Click(object sender, EventArgs e)
{
this.Refresh();
} private void panel1_MouseDown(object sender, MouseEventArgs e)
{
if (e.Button == MouseButtons.Left)
{
a = true;
}
} private void panel1_MouseMove(object sender, MouseEventArgs e)
{
if (a)
{
if (myGraphics == null)
{
myGraphics = pictureBox1.CreateGraphics();
}
//myGraphics = this.CreateGraphics();
if (i == 0)
{
newpo[0].X = e.X;
newpo[0].Y = e.Y;
myGraphics.DrawEllipse(myPen, newpo[0].X, newpo[0].Y, 2, 2);
i++;
}
else if (i > 0 && i < 500)
{
newpo[i].X = e.X;
newpo[i].Y = e.Y;
myGraphics.DrawLine(myPen, newpo[i - 1], newpo[i]);
i++;
}
else if (i == 500)
{
i = 0;
newpo[0].X = e.X;
newpo[0].Y = e.Y;
myGraphics.DrawLine(myPen, newpo[499], newpo[0]);
i++;
} }
} private void panel1_MouseUp(object sender, MouseEventArgs e)
{
a = false;
i = 0;
} private void button2_Click(object sender, EventArgs e)
{
//picturebox的Graphics转成image
}
}
}
请教
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;namespace WindowsApplication1
{
public partial class Form1 : Form
{
bool a = false;
static int i = 0;
Point[] newpo = new Point[500];
Pen myPen = new Pen(Color.Black, 3);
Graphics myGraphics ;
public Bitmap m_bmpPic;
public Image img;
public Form1()
{
InitializeComponent();
} private void button1_Click(object sender, EventArgs e)
{
this.Refresh();
} private void panel1_MouseDown(object sender, MouseEventArgs e)
{
if (e.Button == MouseButtons.Left)
{
a = true;
}
} private void panel1_MouseMove(object sender, MouseEventArgs e)
{
if (a)
{
if (myGraphics == null)
{
myGraphics = pictureBox1.CreateGraphics();
}
//myGraphics = this.CreateGraphics();
if (i == 0)
{
newpo[0].X = e.X;
newpo[0].Y = e.Y;
myGraphics.DrawEllipse(myPen, newpo[0].X, newpo[0].Y, 2, 2);
i++;
}
else if (i > 0 && i < 500)
{
newpo[i].X = e.X;
newpo[i].Y = e.Y;
myGraphics.DrawLine(myPen, newpo[i - 1], newpo[i]);
i++;
}
else if (i == 500)
{
i = 0;
newpo[0].X = e.X;
newpo[0].Y = e.Y;
myGraphics.DrawLine(myPen, newpo[499], newpo[0]);
i++;
} }
} private void panel1_MouseUp(object sender, MouseEventArgs e)
{
a = false;
i = 0;
} private void button2_Click(object sender, EventArgs e)
{
//picturebox的Graphics转成image
}
}
}
這樣獲取
g.DrawImage(oImage,new Rectangle(0,0,tWidth,tHeight),new Rectangle(0,0,oWidth,oHeight),GraphicsUnit.Pixel);