在Form1的頂部我所做的:Bitmap bmp;
Paint事件我畫的pictureBox
,也給bmp
文件:如何將pictureBox1中的當前幀/圖像保存爲位圖文件?
private void pictureBox1_Paint(object sender, System.Windows.Forms.PaintEventArgs e)
{
SolidBrush brush;
Pen p = null;
Point connectionPointStart;
Point connectionPointEnd;
Graphics g = e.Graphics;
bmp = new Bitmap(pictureBox1.Width, pictureBox1.Height);
Graphics bitmapGraphics = Graphics.FromImage(bmp);
//g.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.AntiAlias;
moveCounter++;
label6.Text = moveCounter.ToString();
brush = new SolidBrush(Color.Red);
p = new Pen(brush);
for (int idx = 0; idx < wireObject1._point_X.Count; ++idx)
{
Point dPoint = new Point((int)wireObject1._point_X[idx], (int)wireObject1._point_Y[idx]);
dPoint.X = dPoint.X - 5; // was - 2
dPoint.Y = dPoint.Y - 5; // was - 2
Rectangle rect = new Rectangle(dPoint, new Size(10, 10));
g.FillEllipse(brush, rect);
bitmapGraphics.FillEllipse(brush, rect);
// g.FillEllipse(brush, rect);
}
for (int i = 0; i < wireObject1._connectionstart.Count; i++)
{
int startIndex = wireObject1._connectionstart[i];
int endIndex = wireObject1._connectionend[i];
connectionPointStart = new Point((int)wireObject1._point_X[startIndex], (int)wireObject1._point_Y[startIndex]);
connectionPointEnd = new Point((int)wireObject1._point_X[endIndex], (int)wireObject1._point_Y[endIndex]);
p.Width = 2;
g.DrawLine(p, connectionPointStart, connectionPointEnd);
bitmapGraphics.DrawLine(p, connectionPointStart, connectionPointEnd);
}
}
我的bmp文件油漆事件做了一個新的實例。我也爲bmp文件創建一個新的圖形變量。每一個地方,我繪製或填充橢圓的pictureBox我也把它繪製到BMP文件。
現在保存功能我所做的:
private void SavePictureBoxToBitmap()
{
//PbToBitmap++;
//String tempFile = @"d:\PictureBoxToBitmap\" + PbToBitmap.ToString("D6") + bmp;
bmp.Save(@"d:\PictureBoxToBitmap\bit.bmp");
}
如果即時通訊做bmp.Save它會保存到硬盤上的白色bmp文件圖紙內唯一。如果我正在做pictureBox1.Image.Save,它只會將保存在硬盤上的圖片文件放在圖片框中,而沒有繪圖。
我該如何組合它,所以我會做一個保存行/命令,它將創建一個與pictureBox圖像和圖紙在硬盤上的BMP文件?
Graphics gfx = Graphics.FromImage(pictureBox1.Image)
然後通過使用GFX實例,例如畫上了圖片框的事情:
您確實有寫入權限'd:\'? (它會碰巧是CD驅動器?) – Ryan
minitech D:是我的第二個硬盤。 – user1477444