Commit dbc6add8 SK

选择框拖动

1 个父辈 90fb296f
......@@ -89,8 +89,10 @@ namespace AOI
var srcRect = new RectangleF(srcLocation.X, srcLocation.Y, resultWidth, resultHeight);
using (Graphics g = Graphics.FromImage(result))
{
//g.Clear(Color.Transparent);
g.DrawImage(maskImg, dstRect, srcRect, GraphicsUnit.Pixel);
}
result.MakeTransparent(Color.White);
return result;
}
return null;
......
......@@ -53,13 +53,13 @@ namespace AOI
int num = GetBlobNum(imageToCheck, out cutImg, out Image dstImg, out List<CvBlob> blobList);
resultBean.currentRoiImage = cutImg;
bool result = false;
if (num > minNum)
if (num >= minNum)
{
if(maxNum <= 0)
{
result = true;
}
else if(num < maxNum)
else if(num <= maxNum)
{
result = true;
}
......@@ -107,13 +107,13 @@ namespace AOI
blobList = blobs.Values.ToList();
dstCutImg = ImageUtil.ToImage(threshMat);
List<CvBlob> resultBlobs = blobList.Where(b => {
if (b.Area > minArea)
if (b.Area >= minArea)
{
if (maxArea <= 0 )
{
return true;
}
else if (b.Area < maxArea)
else if (b.Area <= maxArea)
{
return true;
}
......
......@@ -167,6 +167,7 @@ namespace AccAOI
this.imageBox1.DragHandleSize = 9;
this.imageBox1.Location = new System.Drawing.Point(625, 40);
this.imageBox1.Name = "imageBox1";
this.imageBox1.SelectionColor = System.Drawing.Color.Blue;
this.imageBox1.SelectionMode = Acc.ImageBox.ImageBoxSelectionMode.Rectangle;
this.imageBox1.Size = new System.Drawing.Size(637, 592);
this.imageBox1.TabIndex = 4;
......
......@@ -78,7 +78,9 @@ namespace Acc.ImageBox
PointF[] points = this.SelectionRegion.PathPoints;
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))
{
pathPoint = p;
......@@ -407,10 +409,11 @@ namespace Acc.ImageBox
/// <param name="pointf"></param>
protected virtual void DrawDragHandle(Graphics graphics, PointF pointf)
{
float left = pointf.X - this.DragHandleSize / 2;
float top = pointf.Y - this.DragHandleSize / 2;
float width = this.DragHandleSize;
float height = this.DragHandleSize;
float size = (float)(this.DragHandleSize);
float left = pointf.X - size / 2;
float top = pointf.Y - size / 2;
float width = size;
float height = size;
Pen outerPen = SystemPens.WindowFrame;
Brush innerBrush = SystemBrushes.Window;
......@@ -669,10 +672,21 @@ namespace Acc.ImageBox
Point startPoint = this.PointToImage(this.DragOrigin, true);
Point endPoint = this.PointToImage(cursorPosition, true);
Matrix matrix = new Matrix();
float scaleX = endPoint.X * 1.0f / startPoint.X;
float scaleY = endPoint.Y * 1.0f / startPoint.Y;
matrix.Scale(scaleX, scaleY);
//float scaleX = endPoint.X * 1.0f / startPoint.X;
//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(scale, scale);
path.Transform(matrix);
var oldBounds = this.SelectionRegion.GetBounds();
......
......@@ -82,6 +82,8 @@ namespace Acc.ImageBox
private Color _selectionColor;
private bool _selectionFill;
private ImageBoxSelectionMode _selectionMode;
private GraphicsPath _selectionRegion = new GraphicsPath();
......@@ -1503,6 +1505,26 @@ namespace Acc.ImageBox
}
/// <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.
/// </summary>
/// <value>
......@@ -3196,9 +3218,9 @@ namespace Acc.ImageBox
matrix.Translate(offsetX, offsetY);
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);
}
......
支持 Markdown 格式
你添加了 0 到此讨论。请谨慎行事。
Finish editing this message first!