实现重绘
This commit is contained in:
@@ -63,7 +63,7 @@ namespace Camera
|
||||
this.picBoxCamera.Location = new System.Drawing.Point(0, 0);
|
||||
this.picBoxCamera.Name = "picBoxCamera";
|
||||
this.picBoxCamera.Size = new System.Drawing.Size(700, 515);
|
||||
this.picBoxCamera.SizeMode = System.Windows.Forms.PictureBoxSizeMode.StretchImage;
|
||||
this.picBoxCamera.SizeMode = System.Windows.Forms.PictureBoxSizeMode.Normal;
|
||||
this.picBoxCamera.TabIndex = 0;
|
||||
this.picBoxCamera.TabStop = false;
|
||||
this.picBoxCamera.Paint += new System.Windows.Forms.PaintEventHandler(this.PicBoxCamera_Paint);
|
||||
|
||||
@@ -41,12 +41,21 @@ namespace Camera
|
||||
|
||||
public void SetImage(Image image)
|
||||
{
|
||||
if (picBoxCamera.Image != null)
|
||||
try
|
||||
{
|
||||
picBoxCamera.Image.Dispose();
|
||||
if (picBoxCamera.Image != null)
|
||||
{
|
||||
picBoxCamera.Image.Dispose();
|
||||
}
|
||||
Bitmap newImage = new Bitmap(image.Width, image.Height);
|
||||
using (Graphics g = Graphics.FromImage(newImage))
|
||||
{
|
||||
g.DrawImage(image, 0, 0);
|
||||
}
|
||||
picBoxCamera.Image = newImage;
|
||||
picBoxCamera.Invalidate();
|
||||
}
|
||||
picBoxCamera.Image = (Image)image.Clone();
|
||||
picBoxCamera.Invalidate();
|
||||
catch { }
|
||||
}
|
||||
|
||||
public void SetConfigPath(string path)
|
||||
@@ -184,11 +193,20 @@ namespace Camera
|
||||
|
||||
private void UpdateImage(Image image)
|
||||
{
|
||||
if (picBoxCamera.Image != null)
|
||||
try
|
||||
{
|
||||
picBoxCamera.Image.Dispose();
|
||||
if (picBoxCamera.Image != null)
|
||||
{
|
||||
picBoxCamera.Image.Dispose();
|
||||
}
|
||||
Bitmap newImage = new Bitmap(image.Width, image.Height);
|
||||
using (Graphics g = Graphics.FromImage(newImage))
|
||||
{
|
||||
g.DrawImage(image, 0, 0);
|
||||
}
|
||||
picBoxCamera.Image = newImage;
|
||||
}
|
||||
picBoxCamera.Image = image;
|
||||
catch { }
|
||||
}
|
||||
|
||||
private void UpdateDataGridView()
|
||||
@@ -216,8 +234,16 @@ namespace Camera
|
||||
|
||||
private void PicBoxCamera_Paint(object sender, PaintEventArgs e)
|
||||
{
|
||||
Image currentImage = picBoxCamera.Image;
|
||||
if (currentImage == null) return;
|
||||
Image currentImage = null;
|
||||
try
|
||||
{
|
||||
currentImage = picBoxCamera.Image;
|
||||
if (currentImage == null) return;
|
||||
}
|
||||
catch
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
int imageWidth = 0, imageHeight = 0;
|
||||
bool imageValid = false;
|
||||
@@ -232,12 +258,17 @@ namespace Camera
|
||||
}
|
||||
catch
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
if (!imageValid) return;
|
||||
|
||||
Graphics g = e.Graphics;
|
||||
g.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.AntiAlias;
|
||||
g.InterpolationMode = System.Drawing.Drawing2D.InterpolationMode.HighQualityBicubic;
|
||||
|
||||
Rectangle destRect = new Rectangle(0, 0, picBoxCamera.ClientSize.Width, picBoxCamera.ClientSize.Height);
|
||||
g.DrawImage(currentImage, destRect, 0, 0, currentImage.Width, currentImage.Height, GraphicsUnit.Pixel);
|
||||
|
||||
float scaleX = (float)picBoxCamera.ClientSize.Width / imageWidth;
|
||||
float scaleY = (float)picBoxCamera.ClientSize.Height / imageHeight;
|
||||
@@ -498,7 +529,7 @@ namespace Camera
|
||||
{
|
||||
_camera.SetLedZone(newZone);
|
||||
}
|
||||
picBoxCamera.Invalidate();
|
||||
picBoxCamera.Update();
|
||||
}
|
||||
}
|
||||
else if (_isMoving)
|
||||
@@ -526,7 +557,7 @@ namespace Camera
|
||||
{
|
||||
_camera.SetLedZone(newZone);
|
||||
}
|
||||
picBoxCamera.Invalidate();
|
||||
picBoxCamera.Update();
|
||||
}
|
||||
}
|
||||
else
|
||||
|
||||
Reference in New Issue
Block a user