Commit dbc6add8 SK

选择框拖动

1 个父辈 90fb296f
...@@ -89,8 +89,10 @@ namespace AOI ...@@ -89,8 +89,10 @@ namespace AOI
var srcRect = new RectangleF(srcLocation.X, srcLocation.Y, resultWidth, resultHeight); var srcRect = new RectangleF(srcLocation.X, srcLocation.Y, resultWidth, resultHeight);
using (Graphics g = Graphics.FromImage(result)) using (Graphics g = Graphics.FromImage(result))
{ {
//g.Clear(Color.Transparent);
g.DrawImage(maskImg, dstRect, srcRect, GraphicsUnit.Pixel); g.DrawImage(maskImg, dstRect, srcRect, GraphicsUnit.Pixel);
} }
result.MakeTransparent(Color.White);
return result; return result;
} }
return null; return null;
......
...@@ -53,13 +53,13 @@ namespace AOI ...@@ -53,13 +53,13 @@ namespace AOI
int num = GetBlobNum(imageToCheck, out cutImg, out Image dstImg, out List<CvBlob> blobList); int num = GetBlobNum(imageToCheck, out cutImg, out Image dstImg, out List<CvBlob> blobList);
resultBean.currentRoiImage = cutImg; resultBean.currentRoiImage = cutImg;
bool result = false; bool result = false;
if (num > minNum) if (num >= minNum)
{ {
if(maxNum <= 0) if(maxNum <= 0)
{ {
result = true; result = true;
} }
else if(num < maxNum) else if(num <= maxNum)
{ {
result = true; result = true;
} }
...@@ -107,13 +107,13 @@ namespace AOI ...@@ -107,13 +107,13 @@ namespace AOI
blobList = blobs.Values.ToList(); blobList = blobs.Values.ToList();
dstCutImg = ImageUtil.ToImage(threshMat); dstCutImg = ImageUtil.ToImage(threshMat);
List<CvBlob> resultBlobs = blobList.Where(b => { List<CvBlob> resultBlobs = blobList.Where(b => {
if (b.Area > minArea) if (b.Area >= minArea)
{ {
if (maxArea <= 0 ) if (maxArea <= 0 )
{ {
return true; return true;
} }
else if (b.Area < maxArea) else if (b.Area <= maxArea)
{ {
return true; return true;
} }
......
...@@ -167,6 +167,7 @@ namespace AccAOI ...@@ -167,6 +167,7 @@ namespace AccAOI
this.imageBox1.DragHandleSize = 9; this.imageBox1.DragHandleSize = 9;
this.imageBox1.Location = new System.Drawing.Point(625, 40); this.imageBox1.Location = new System.Drawing.Point(625, 40);
this.imageBox1.Name = "imageBox1"; this.imageBox1.Name = "imageBox1";
this.imageBox1.SelectionColor = System.Drawing.Color.Blue;
this.imageBox1.SelectionMode = Acc.ImageBox.ImageBoxSelectionMode.Rectangle; this.imageBox1.SelectionMode = Acc.ImageBox.ImageBoxSelectionMode.Rectangle;
this.imageBox1.Size = new System.Drawing.Size(637, 592); this.imageBox1.Size = new System.Drawing.Size(637, 592);
this.imageBox1.TabIndex = 4; this.imageBox1.TabIndex = 4;
......
...@@ -78,7 +78,9 @@ namespace Acc.ImageBox ...@@ -78,7 +78,9 @@ namespace Acc.ImageBox
PointF[] points = this.SelectionRegion.PathPoints; PointF[] points = this.SelectionRegion.PathPoints;
foreach (PointF p in points) foreach (PointF p in points)
{ {
RectangleF recf = new RectangleF(p.X - this.DragHandleSize / 2, p.Y - this.DragHandleSize / 2, this.DragHandleSize, this.DragHandleSize); float size =(float) (this.DragHandleSize / this.ZoomFactor);
//size = (float)this.DragHandleSize;
RectangleF recf = new RectangleF(p.X - size / 2, p.Y - size / 2, size, size);
if (recf.Contains(imagePoint)) if (recf.Contains(imagePoint))
{ {
pathPoint = p; pathPoint = p;
...@@ -407,10 +409,11 @@ namespace Acc.ImageBox ...@@ -407,10 +409,11 @@ namespace Acc.ImageBox
/// <param name="pointf"></param> /// <param name="pointf"></param>
protected virtual void DrawDragHandle(Graphics graphics, PointF pointf) protected virtual void DrawDragHandle(Graphics graphics, PointF pointf)
{ {
float left = pointf.X - this.DragHandleSize / 2; float size = (float)(this.DragHandleSize);
float top = pointf.Y - this.DragHandleSize / 2; float left = pointf.X - size / 2;
float width = this.DragHandleSize; float top = pointf.Y - size / 2;
float height = this.DragHandleSize; float width = size;
float height = size;
Pen outerPen = SystemPens.WindowFrame; Pen outerPen = SystemPens.WindowFrame;
Brush innerBrush = SystemBrushes.Window; Brush innerBrush = SystemBrushes.Window;
...@@ -669,10 +672,21 @@ namespace Acc.ImageBox ...@@ -669,10 +672,21 @@ namespace Acc.ImageBox
Point startPoint = this.PointToImage(this.DragOrigin, true); Point startPoint = this.PointToImage(this.DragOrigin, true);
Point endPoint = this.PointToImage(cursorPosition, true); Point endPoint = this.PointToImage(cursorPosition, true);
Matrix matrix = new Matrix(); Matrix matrix = new Matrix();
float scaleX = endPoint.X * 1.0f / startPoint.X; //float scaleX = endPoint.X * 1.0f / startPoint.X;
float scaleY = endPoint.Y * 1.0f / startPoint.Y; //float scaleY = endPoint.Y * 1.0f / startPoint.Y;
//靠近中心点为缩小
var selectionBounds = this.SelectionRegion.GetBounds();
float centerX = selectionBounds.X + selectionBounds.Width / 2;
float centerY = selectionBounds.Y + selectionBounds.Height / 2;
double endToCenter = Math.Sqrt(Math.Pow(endPoint.X - centerX, 2) + Math.Pow(endPoint.Y - centerY, 2));
double startToCenter = Math.Sqrt(Math.Pow(startPoint.X - centerX, 2) + Math.Pow(startPoint.Y - centerY, 2));
float scale = scale = (float)(endToCenter / startToCenter);
//if (endToCenter > startToCenter)
//{
// scale = (float)(startToCenter/endToCenter);
//}
matrix.Scale(scaleX, scaleY); matrix.Scale(scale, scale);
path.Transform(matrix); path.Transform(matrix);
var oldBounds = this.SelectionRegion.GetBounds(); var oldBounds = this.SelectionRegion.GetBounds();
......
...@@ -82,6 +82,8 @@ namespace Acc.ImageBox ...@@ -82,6 +82,8 @@ namespace Acc.ImageBox
private Color _selectionColor; private Color _selectionColor;
private bool _selectionFill;
private ImageBoxSelectionMode _selectionMode; private ImageBoxSelectionMode _selectionMode;
private GraphicsPath _selectionRegion = new GraphicsPath(); private GraphicsPath _selectionRegion = new GraphicsPath();
...@@ -1503,6 +1505,26 @@ namespace Acc.ImageBox ...@@ -1503,6 +1505,26 @@ namespace Acc.ImageBox
} }
/// <summary> /// <summary>
/// Gets or sets the color of selection regions.
/// </summary>
/// <value>
/// The color of selection regions.
/// </value>
[Category("Appearance")]
[DefaultValue(false)]
public virtual bool SelectionFill
{
get { return _selectionFill; }
set
{
if (this._selectionFill != value)
{
_selectionFill = value;
}
}
}
/// <summary>
/// Gets or sets the selection mode. /// Gets or sets the selection mode.
/// </summary> /// </summary>
/// <value> /// <value>
...@@ -3196,9 +3218,9 @@ namespace Acc.ImageBox ...@@ -3196,9 +3218,9 @@ namespace Acc.ImageBox
matrix.Translate(offsetX, offsetY); matrix.Translate(offsetX, offsetY);
newPath.Transform(matrix); newPath.Transform(matrix);
if (needFill) if (needFill && this.SelectionFill)
{ {
using (Brush brush = new SolidBrush(Color.FromArgb(128, color))) using (Brush brush = new SolidBrush(Color.FromArgb(80, color)))
{ {
g.FillPath(brush, newPath); g.FillPath(brush, newPath);
} }
......
支持 Markdown 格式
你添加了 0 到此讨论。请谨慎行事。
Finish editing this message first!