diff --git a/.cr/personal/FavoritesList/List.xml b/.cr/personal/FavoritesList/List.xml
new file mode 100644
index 000000000..a60e5ed6c
--- /dev/null
+++ b/.cr/personal/FavoritesList/List.xml
@@ -0,0 +1,6 @@
+
+
+
+
+
+
\ No newline at end of file
diff --git a/src/OpenCvSharp.DebuggerVisualizers/ImageViewer.cs b/src/OpenCvSharp.DebuggerVisualizers/ImageViewer.cs
index 4f7833ffd..a9df71a51 100644
--- a/src/OpenCvSharp.DebuggerVisualizers/ImageViewer.cs
+++ b/src/OpenCvSharp.DebuggerVisualizers/ImageViewer.cs
@@ -11,6 +11,15 @@ public partial class ImageViewer : Form
public ImageViewer()
{
InitializeComponent();
+ this.MouseWheel += MainForm_MouseWheel;
+ this.FormBorderStyle = FormBorderStyle.FixedSingle;
+ this.MouseMove += MainForm_MouseMove;
+ this.MouseDown += MainForm_MouseDown;
+
+ this.MouseUp += MainForm_MouseUp;
+
+ this.DoubleBuffered = true;
+
}
public ImageViewer(MatProxy proxy)
@@ -36,48 +45,120 @@ private void DisposeBitmap()
{
bitmap?.Dispose();
}
+
- protected override void OnLoad(EventArgs e)
+ ///
+ /// 最小缩放尺寸
+ ///
+ int minZoom = 1;
+
+ ///
+ /// 缩放尺寸
+ ///
+ int zoom = 1;
+ ///
+ /// 滚动缩放图片,像素级别放大,不模糊
+ ///
+ ///
+ ///
+ private void MainForm_MouseWheel(object sender, MouseEventArgs e)
{
- base.OnLoad(e);
+ if (e.Delta > 0)
+ {
+ zoom++;
+ }
+ else
+ { zoom--; }
- var ratio = SetClientSize(new System.Drawing.Size(bitmap.Width, bitmap.Height));
- DisplayRatio(ratio);
+ if (zoom < minZoom)
+ {
+ zoom = minZoom;
+ }
+ else if (zoom > 100)
+ {
+ zoom = 100;
+ }
- pictureBox.Image = bitmap;
+ Zoom();
}
-
///
- /// ClientSizeを画面からはみ出ない大きさに調整して設定する.
+ /// 缩放图片的时候,更改winform的大小.
///
- ///
- private double SetClientSize(System.Drawing.Size size)
+ private void Zoom()
{
- var screenSize = Screen.PrimaryScreen.Bounds.Size;
- var ratioX = (double)screenSize.Width / size.Width;
- var ratioY = (double)screenSize.Height / size.Height;
- var ratio = Math.Max(ratioX, ratioY);
- ratio = ReformRatio(ratio);
- size.Width = Convert.ToInt32(size.Width * ratio);
- size.Height = Convert.ToInt32(size.Height * ratio);
- ClientSize = size;
- pictureBox.Size = size;
- return ratio;
+ if (bitmap != null)
+ {
+ var bitmap2 = new Bitmap(bitmap, bitmap.Width * zoom, bitmap.Height * zoom);
+ using (Graphics graphics = Graphics.FromImage(bitmap2))
+ {
+ graphics.InterpolationMode = System.Drawing.Drawing2D.InterpolationMode.NearestNeighbor;
+ graphics.PixelOffsetMode = System.Drawing.Drawing2D.PixelOffsetMode.Half;
+ graphics.DrawImage(bitmap, new Rectangle(0, 0, bitmap2.Width, bitmap2.Height));
+ }
+ this.BackgroundImage = bitmap2;
+ this.ClientSize = bitmap2.Size;
+ }
}
+ protected override void OnLoad(EventArgs e)
+ {
+ base.OnLoad(e);
+
+ this.BackgroundImage = bitmap;
+ this.BackgroundImageLayout = ImageLayout.Center;
+
+ while (BackgroundImage.Size.Width < 120|| BackgroundImage.Size.Height<80)
+ {
+ zoom++;
+ Zoom();
+ minZoom = zoom; }
+ this.ClientSize = BackgroundImage.Size;
+
+ }
+ private void MainForm_MouseMove(object sender, MouseEventArgs e)
+ {
+ //获取当前鼠标处的像素点的值
+
+ if (isDragging)
+ {
+ this.Left += e.X - offsetX;
+ this.Top += e.Y - offsetY;
+ }
+ else if (bitmap != null)
+ {
+ try
+ {
+ var color = bitmap.GetPixel(e.X / zoom, e.Y / zoom);
+ this.Text = $"看图-X:{e.X / zoom} Y:{e.Y / zoom} R:{color.R} G:{color.G} B:{color.B}";
+ }
+ catch (Exception ex)
+ {
+
+ }
- private double ReformRatio(double ratio)
+ }
+
+ }
+ private bool isDragging;
+ private int offsetX;
+ private int offsetY;
+ private void MainForm_MouseDown(object sender, MouseEventArgs e)
{
- var v1 = ratio;
- var lg2 = Math.Log(v1, 2);
- var lgz = Math.Floor(lg2);
- var pw = lgz == lg2 ? lgz - 1 : lgz;
- var r = Math.Pow(2, pw);
- return r;
+ if (e.Button == MouseButtons.Left)
+ {
+ isDragging = true;
+ offsetX = e.X;
+ offsetY = e.Y;
+ }
}
- private void DisplayRatio(double ratio)
+
+
+ private void MainForm_MouseUp(object sender, MouseEventArgs e)
{
- Text = $@"ImageViewer Zoom: {ratio:P1}";
+ if (e.Button == MouseButtons.Left)
+ {
+ isDragging = false;
+ }
}
}
}
diff --git a/src/OpenCvSharp.DebuggerVisualizers/ImageViewer.designer.cs b/src/OpenCvSharp.DebuggerVisualizers/ImageViewer.designer.cs
index 331890f0d..c62552691 100644
--- a/src/OpenCvSharp.DebuggerVisualizers/ImageViewer.designer.cs
+++ b/src/OpenCvSharp.DebuggerVisualizers/ImageViewer.designer.cs
@@ -29,39 +29,22 @@ protected override void Dispose(bool disposing)
///
private void InitializeComponent()
{
- this.pictureBox = new System.Windows.Forms.PictureBox();
- ((System.ComponentModel.ISupportInitialize)(this.pictureBox)).BeginInit();
- this.SuspendLayout();
- //
- // pictureBox
- //
- this.pictureBox.BackColor = System.Drawing.Color.Black;
- this.pictureBox.Dock = System.Windows.Forms.DockStyle.Fill;
- this.pictureBox.Location = new System.Drawing.Point(0, 0);
- this.pictureBox.Name = "pictureBox";
- this.pictureBox.Size = new System.Drawing.Size(384, 263);
- this.pictureBox.SizeMode = System.Windows.Forms.PictureBoxSizeMode.Zoom;
- this.pictureBox.TabIndex = 0;
- this.pictureBox.TabStop = false;
- //
- // ImageViewer
- //
- this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 12F);
- this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
- this.AutoScroll = true;
- this.ClientSize = new System.Drawing.Size(384, 263);
- this.Controls.Add(this.pictureBox);
- this.Name = "ImageViewer";
- this.Text = "ImageViewer";
- ((System.ComponentModel.ISupportInitialize)(this.pictureBox)).EndInit();
- this.ResumeLayout(false);
+ this.SuspendLayout();
+ //
+ // ImageViewer
+ //
+ this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 12F);
+ this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
+ this.AutoScroll = true;
+ this.ClientSize = new System.Drawing.Size(384, 263);
+ this.Name = "ImageViewer";
+ this.Text = "看图";
+ this.ResumeLayout(false);
}
#endregion
- private System.Windows.Forms.PictureBox pictureBox;
-
}
}