Commit 855b5efd LN

新增程序时,导入的图片可以编辑和旋转

1 个父辈 4fdb58b0
...@@ -2801,5 +2801,10 @@ ...@@ -2801,5 +2801,10 @@
<data name = "FrmScanPutCom_label1_Text" xml:space = "preserve"> <value> Tray Position: </value> </data> <data name = "FrmScanPutCom_label1_Text" xml:space = "preserve"> <value> Tray Position: </value> </data>
<data name = "FrmScanPutCom_label3_Text" xml:space = "preserve"> <value> Quantity: </value> </data> <data name = "FrmScanPutCom_label3_Text" xml:space = "preserve"> <value> Quantity: </value> </data>
<data name = "FrmScanPutCom_btnCancel_Text" xml:space = "preserve"> <value> End </value> </data> <data name = "FrmScanPutCom_btnCancel_Text" xml:space = "preserve"> <value> End </value> </data>
<data name = "NotFindPN" xml:space = "preserve"> <value> PN={0} not found, please scan again </value> </data> <data name = "NotFindPN" xml:space = "preserve"> <value> PN={0} not found, please scan again </value> </data>
<data name = "FrmNImageViewer_Text" xml:space = "preserve"> <value> Image Preview </value> </data>
<data name = "FrmNImageViewer_btnCut_Text" xml:space = "preserve"> <value> Cut </value> </data>
<data name = "FrmNImageViewer_btnR_Text" xml:space = "preserve"> <value> Rotate </value> </data>
<data name = "FrmNImageViewer_btnCancel_Text" xml:space = "preserve"> <value> Cancel </value> </data>
<data name = "FrmNImageViewer_btnOK_Text" xml:space = "preserve"> <value> OK </value> </data>
</root> </root>
\ No newline at end of file \ No newline at end of file
...@@ -2780,4 +2780,9 @@ ...@@ -2780,4 +2780,9 @@
<data name = "FrmScanPutCom_label3_Text" xml:space = "preserve"> <value> 数量: </value> </data> <data name = "FrmScanPutCom_label3_Text" xml:space = "preserve"> <value> 数量: </value> </data>
<data name = "FrmScanPutCom_btnCancel_Text" xml:space = "preserve"> <value> 结束 </value> </data> <data name = "FrmScanPutCom_btnCancel_Text" xml:space = "preserve"> <value> 结束 </value> </data>
<data name = "NotFindPN" xml:space = "preserve"> <value> 未找到对应的PN={0},请重新扫码 </value> </data> <data name = "NotFindPN" xml:space = "preserve"> <value> 未找到对应的PN={0},请重新扫码 </value> </data>
<data name = "FrmNImageViewer_Text" xml:space = "preserve"> <value> 图片预览 </value> </data>
<data name = "FrmNImageViewer_btnCut_Text" xml:space = "preserve"> <value> 剪切 </value> </data>
<data name = "FrmNImageViewer_btnR_Text" xml:space = "preserve"> <value> 旋转 </value> </data>
<data name = "FrmNImageViewer_btnCancel_Text" xml:space = "preserve"> <value> 取消 </value> </data>
<data name = "FrmNImageViewer_btnOK_Text" xml:space = "preserve"> <value> 确认 </value> </data>
</root> </root>
\ No newline at end of file \ No newline at end of file
...@@ -3023,5 +3023,10 @@ ...@@ -3023,5 +3023,10 @@
<data name = "FrmScanPutCom_label1_Text" xml:space = "preserve"> <value> 料盘位置: </value> </data> <data name = "FrmScanPutCom_label1_Text" xml:space = "preserve"> <value> 料盘位置: </value> </data>
<data name = "FrmScanPutCom_label3_Text" xml:space = "preserve"> <value> 数量: </value> </data> <data name = "FrmScanPutCom_label3_Text" xml:space = "preserve"> <value> 数量: </value> </data>
<data name = "FrmScanPutCom_btnCancel_Text" xml:space = "preserve"> <value> 结束 </value> </data> <data name = "FrmScanPutCom_btnCancel_Text" xml:space = "preserve"> <value> 结束 </value> </data>
<data name = "NotFindPN" xml:space = "preserve"> <value> 未找到对应的PN={0},请重新扫码 </value> </data> <data name = "NotFindPN" xml:space = "preserve"> <value> 未找到对应的PN={0},请重新扫码 </value> </data>
<data name = "FrmNImageViewer_Text" xml:space = "preserve"> <value> 图片预览 </value> </data>
<data name = "FrmNImageViewer_btnCut_Text" xml:space = "preserve"> <value> 剪切 </value> </data>
<data name = "FrmNImageViewer_btnR_Text" xml:space = "preserve"> <value> 旋转 </value> </data>
<data name = "FrmNImageViewer_btnCancel_Text" xml:space = "preserve"> <value> 取消 </value> </data>
<data name = "FrmNImageViewer_btnOK_Text" xml:space = "preserve"> <value> 确认 </value> </data>
</root> </root>
\ No newline at end of file \ No newline at end of file
...@@ -203,6 +203,12 @@ ...@@ -203,6 +203,12 @@
<Compile Include="frmBoard\FrmBomViewer.Designer.cs"> <Compile Include="frmBoard\FrmBomViewer.Designer.cs">
<DependentUpon>FrmBomViewer.cs</DependentUpon> <DependentUpon>FrmBomViewer.cs</DependentUpon>
</Compile> </Compile>
<Compile Include="frmBoard\FrmNImageViewer.cs">
<SubType>Form</SubType>
</Compile>
<Compile Include="frmBoard\FrmNImageViewer.Designer.cs">
<DependentUpon>FrmNImageViewer.cs</DependentUpon>
</Compile>
<Compile Include="frmBoard\FrmListViewer.cs"> <Compile Include="frmBoard\FrmListViewer.cs">
<SubType>Form</SubType> <SubType>Form</SubType>
</Compile> </Compile>
...@@ -276,12 +282,6 @@ ...@@ -276,12 +282,6 @@
<Compile Include="FrmHistorySearch.Designer.cs"> <Compile Include="FrmHistorySearch.Designer.cs">
<DependentUpon>FrmHistorySearch.cs</DependentUpon> <DependentUpon>FrmHistorySearch.cs</DependentUpon>
</Compile> </Compile>
<Compile Include="frmBoard\FrmImageViewer.cs">
<SubType>Form</SubType>
</Compile>
<Compile Include="frmBoard\FrmImageViewer.Designer.cs">
<DependentUpon>FrmImageViewer.cs</DependentUpon>
</Compile>
<Compile Include="FrmLogin.cs"> <Compile Include="FrmLogin.cs">
<SubType>Form</SubType> <SubType>Form</SubType>
</Compile> </Compile>
...@@ -457,6 +457,9 @@ ...@@ -457,6 +457,9 @@
<EmbeddedResource Include="frmBoard\FrmAddBoard.resx"> <EmbeddedResource Include="frmBoard\FrmAddBoard.resx">
<DependentUpon>FrmAddBoard.cs</DependentUpon> <DependentUpon>FrmAddBoard.cs</DependentUpon>
</EmbeddedResource> </EmbeddedResource>
<EmbeddedResource Include="frmBoard\FrmNImageViewer.resx">
<DependentUpon>FrmNImageViewer.cs</DependentUpon>
</EmbeddedResource>
<EmbeddedResource Include="frmCom\FrmAddCom.resx"> <EmbeddedResource Include="frmCom\FrmAddCom.resx">
<DependentUpon>FrmAddCom.cs</DependentUpon> <DependentUpon>FrmAddCom.cs</DependentUpon>
</EmbeddedResource> </EmbeddedResource>
...@@ -504,9 +507,6 @@ ...@@ -504,9 +507,6 @@
<EmbeddedResource Include="FrmHistorySearch.resx"> <EmbeddedResource Include="FrmHistorySearch.resx">
<DependentUpon>FrmHistorySearch.cs</DependentUpon> <DependentUpon>FrmHistorySearch.cs</DependentUpon>
</EmbeddedResource> </EmbeddedResource>
<EmbeddedResource Include="frmBoard\FrmImageViewer.resx">
<DependentUpon>FrmImageViewer.cs</DependentUpon>
</EmbeddedResource>
<EmbeddedResource Include="FrmLogin.resx"> <EmbeddedResource Include="FrmLogin.resx">
<DependentUpon>FrmLogin.cs</DependentUpon> <DependentUpon>FrmLogin.cs</DependentUpon>
</EmbeddedResource> </EmbeddedResource>
......
...@@ -445,7 +445,7 @@ namespace TSA_V ...@@ -445,7 +445,7 @@ namespace TSA_V
string[] files = openFileDialogImg.FileNames; string[] files = openFileDialogImg.FileNames;
string defPath = Path.GetPathRoot(Application.StartupPath) + @"image\"; string defPath = Path.GetPathRoot(Application.StartupPath) + @"image\";
FrmImageViewer imageViewer; FrmNImageViewer imageViewer;
//List<string> newFiles = FileUtil.FileProcess(openFileDialog.FileNames); //List<string> newFiles = FileUtil.FileProcess(openFileDialog.FileNames);
GerberVS.BoundingBox boxBound = GerberVS.AGerberController.OpenLayers(files, defPath, out string filename); GerberVS.BoundingBox boxBound = GerberVS.AGerberController.OpenLayers(files, defPath, out string filename);
if (boxBound != null && File.Exists(filename)) if (boxBound != null && File.Exists(filename))
...@@ -455,7 +455,7 @@ namespace TSA_V ...@@ -455,7 +455,7 @@ namespace TSA_V
string msg = $"位置左下角({Math.Round(boxBound.Left, 2)},{Math.Round(boxBound.Bottom, 2)})," + string msg = $"位置左下角({Math.Round(boxBound.Left, 2)},{Math.Round(boxBound.Bottom, 2)})," +
$"右上角({Math.Round(boxBound.Right, 2)},{Math.Round(boxBound.Top, 2)}):尺寸:{Math.Round(x, 2)}X{Math.Round(y, 2)}"; $"右上角({Math.Round(boxBound.Right, 2)},{Math.Round(boxBound.Top, 2)}):尺寸:{Math.Round(x, 2)}X{Math.Round(y, 2)}";
LogUtil.info($"gerber文件【{string.Join(",", files)}】成功导入到文件:{filename},{msg}"); LogUtil.info($"gerber文件【{string.Join(",", files)}】成功导入到文件:{filename},{msg}");
imageViewer = new FrmImageViewer(filename); imageViewer = new FrmNImageViewer(filename);
if (!imageViewer.ShowDialog().Equals(DialogResult.Cancel)) if (!imageViewer.ShowDialog().Equals(DialogResult.Cancel))
{ {
int l = (int)Math.Round(x); int l = (int)Math.Round(x);
...@@ -486,7 +486,7 @@ namespace TSA_V ...@@ -486,7 +486,7 @@ namespace TSA_V
string ext = Path.GetExtension(file); string ext = Path.GetExtension(file);
if (fileTypes.Contains(ext.ToLower())) if (fileTypes.Contains(ext.ToLower()))
{ {
imageViewer = new FrmImageViewer(openFileDialogImg.FileName); imageViewer = new FrmNImageViewer(openFileDialogImg.FileName);
if (!imageViewer.ShowDialog().Equals(DialogResult.Cancel)) if (!imageViewer.ShowDialog().Equals(DialogResult.Cancel))
{ {
openFileDialogImg.Tag = true; openFileDialogImg.Tag = true;
...@@ -655,7 +655,7 @@ namespace TSA_V ...@@ -655,7 +655,7 @@ namespace TSA_V
string msg = $"位置左下角({Math.Round(boxBound.Left, 2)},{Math.Round(boxBound.Bottom, 2)})," + string msg = $"位置左下角({Math.Round(boxBound.Left, 2)},{Math.Round(boxBound.Bottom, 2)})," +
$"右上角({Math.Round(boxBound.Right, 2)},{Math.Round(boxBound.Top, 2)}):尺寸:{Math.Round(x, 2)}X{Math.Round(y, 2)}"; $"右上角({Math.Round(boxBound.Right, 2)},{Math.Round(boxBound.Top, 2)}):尺寸:{Math.Round(x, 2)}X{Math.Round(y, 2)}";
LogUtil.info($"gerber文件【{string.Join(",", files)}】成功导入到文件:{filename},{msg}"); LogUtil.info($"gerber文件【{string.Join(",", files)}】成功导入到文件:{filename},{msg}");
FrmImageViewer imageViewer = new FrmImageViewer(filename); FrmNImageViewer imageViewer = new FrmNImageViewer(filename);
DialogResult sureresult = imageViewer.ShowDialog(); DialogResult sureresult = imageViewer.ShowDialog();
if (!sureresult.Equals(DialogResult.Cancel)) if (!sureresult.Equals(DialogResult.Cancel))
{ {
...@@ -742,12 +742,13 @@ namespace TSA_V ...@@ -742,12 +742,13 @@ namespace TSA_V
{ {
string fileName = this.txtImagePath.Text; string fileName = this.txtImagePath.Text;
if ( File.Exists(fileName)) if ( File.Exists(fileName))
{ {
FrmImageViewer imageViewer = new FrmImageViewer(fileName); FrmNImageViewer imageViewer = new FrmNImageViewer(fileName);
//FrmImageViewer imageViewer = new FrmImageViewer(fileName);
DialogResult sureresult = imageViewer.ShowDialog(); DialogResult sureresult = imageViewer.ShowDialog();
if (sureresult.Equals(DialogResult.Cancel)) if (sureresult.Equals(DialogResult.Cancel))
{ {
this.txtImagePath.Text = ""; //this.txtImagePath.Text = "";
} }
} }
} }
......
namespace TSA_V
{
partial class FrmNImageViewer
{
/// <summary>
/// Required designer variable.
/// </summary>
private System.ComponentModel.IContainer components = null;
/// <summary>
/// Clean up any resources being used.
/// </summary>
/// <param name="disposing">true if managed resources should be disposed; otherwise, false.</param>
protected override void Dispose(bool disposing)
{
if (disposing && (components != null))
{
components.Dispose();
}
base.Dispose(disposing);
}
#region Windows Form Designer generated code
/// <summary>
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// </summary>
private void InitializeComponent()
{
this.panel1 = new System.Windows.Forms.Panel();
this.picViewer = new Acc.ImageBox.AccImageBox();
this.btnOK = new System.Windows.Forms.Button();
this.btnCancel = new System.Windows.Forms.Button();
this.btnR = new System.Windows.Forms.Button();
this.numRValue = new System.Windows.Forms.NumericUpDown();
this.btnCut = new System.Windows.Forms.Button();
this.panel1.SuspendLayout();
((System.ComponentModel.ISupportInitialize)(this.numRValue)).BeginInit();
this.SuspendLayout();
//
// panel1
//
this.panel1.Anchor = ((System.Windows.Forms.AnchorStyles)((((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom)
| System.Windows.Forms.AnchorStyles.Left)
| System.Windows.Forms.AnchorStyles.Right)));
this.panel1.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Zoom;
this.panel1.Controls.Add(this.picViewer);
this.panel1.Location = new System.Drawing.Point(5, 5);
this.panel1.Name = "panel1";
this.panel1.Size = new System.Drawing.Size(704, 430);
this.panel1.TabIndex = 0;
//
// picViewer
//
this.picViewer.AllowDoubleClick = true;
this.picViewer.BackColor = System.Drawing.Color.Black;
this.picViewer.Dock = System.Windows.Forms.DockStyle.Fill;
this.picViewer.DragHandleSize = 9;
this.picViewer.Font = new System.Drawing.Font("微软雅黑", 9F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(134)));
this.picViewer.GridColor = System.Drawing.Color.Black;
this.picViewer.GridColorAlternate = System.Drawing.Color.Black;
this.picViewer.ImageBorderColor = System.Drawing.SystemColors.ActiveCaptionText;
this.picViewer.Location = new System.Drawing.Point(0, 0);
this.picViewer.Name = "picViewer";
this.picViewer.SelectionFill = true;
this.picViewer.SelectionMode = Acc.ImageBox.ImageBoxSelectionMode.Rectangle;
this.picViewer.Size = new System.Drawing.Size(704, 430);
this.picViewer.TabIndex = 299;
//
// btnOK
//
this.btnOK.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right)));
this.btnOK.FlatStyle = System.Windows.Forms.FlatStyle.Flat;
this.btnOK.Font = new System.Drawing.Font("微软雅黑", 12F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(134)));
this.btnOK.Location = new System.Drawing.Point(458, 445);
this.btnOK.Name = "btnOK";
this.btnOK.Size = new System.Drawing.Size(120, 45);
this.btnOK.TabIndex = 284;
this.btnOK.Text = "确认";
this.btnOK.UseVisualStyleBackColor = true;
this.btnOK.Click += new System.EventHandler(this.btnOK_Click);
//
// btnCancel
//
this.btnCancel.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right)));
this.btnCancel.FlatStyle = System.Windows.Forms.FlatStyle.Flat;
this.btnCancel.Font = new System.Drawing.Font("微软雅黑", 12F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(134)));
this.btnCancel.Location = new System.Drawing.Point(584, 445);
this.btnCancel.Name = "btnCancel";
this.btnCancel.Size = new System.Drawing.Size(120, 45);
this.btnCancel.TabIndex = 285;
this.btnCancel.Text = "取消";
this.btnCancel.UseVisualStyleBackColor = true;
this.btnCancel.Click += new System.EventHandler(this.btnCancel_Click);
//
// btnR
//
this.btnR.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left)));
this.btnR.FlatStyle = System.Windows.Forms.FlatStyle.Flat;
this.btnR.Font = new System.Drawing.Font("微软雅黑", 12F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(134)));
this.btnR.Location = new System.Drawing.Point(65, 445);
this.btnR.Name = "btnR";
this.btnR.Size = new System.Drawing.Size(120, 45);
this.btnR.TabIndex = 286;
this.btnR.Text = "旋转";
this.btnR.UseVisualStyleBackColor = true;
this.btnR.Click += new System.EventHandler(this.btnR_Click);
//
// numRValue
//
this.numRValue.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left)));
this.numRValue.Font = new System.Drawing.Font("微软雅黑", 14.25F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(134)));
this.numRValue.Location = new System.Drawing.Point(5, 452);
this.numRValue.Maximum = new decimal(new int[] {
180,
0,
0,
0});
this.numRValue.Minimum = new decimal(new int[] {
1,
0,
0,
0});
this.numRValue.Name = "numRValue";
this.numRValue.Size = new System.Drawing.Size(54, 33);
this.numRValue.TabIndex = 287;
this.numRValue.Value = new decimal(new int[] {
90,
0,
0,
0});
//
// btnCut
//
this.btnCut.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left)));
this.btnCut.FlatStyle = System.Windows.Forms.FlatStyle.Flat;
this.btnCut.Font = new System.Drawing.Font("微软雅黑", 12F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(134)));
this.btnCut.Location = new System.Drawing.Point(191, 445);
this.btnCut.Name = "btnCut";
this.btnCut.Size = new System.Drawing.Size(120, 45);
this.btnCut.TabIndex = 288;
this.btnCut.Text = "剪切";
this.btnCut.UseVisualStyleBackColor = true;
this.btnCut.Click += new System.EventHandler(this.btnCut_Click);
//
// FrmNImageViewer
//
this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 12F);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.ClientSize = new System.Drawing.Size(716, 502);
this.Controls.Add(this.btnCut);
this.Controls.Add(this.numRValue);
this.Controls.Add(this.btnR);
this.Controls.Add(this.btnCancel);
this.Controls.Add(this.btnOK);
this.Controls.Add(this.panel1);
this.MaximizeBox = true;
this.MinimizeBox = true;
this.Name = "FrmNImageViewer";
this.Text = "图片预览";
this.TopMost = true;
this.WindowState = System.Windows.Forms.FormWindowState.Maximized;
this.Load += new System.EventHandler(this.FrmImageViewer_Load);
this.panel1.ResumeLayout(false);
((System.ComponentModel.ISupportInitialize)(this.numRValue)).EndInit();
this.ResumeLayout(false);
}
#endregion
private System.Windows.Forms.Panel panel1;
private System.Windows.Forms.Button btnOK;
private System.Windows.Forms.Button btnCancel;
private System.Windows.Forms.Button btnR;
private System.Windows.Forms.NumericUpDown numRValue;
private Acc.ImageBox.AccImageBox picViewer;
private System.Windows.Forms.Button btnCut;
}
}
\ No newline at end of file \ No newline at end of file
using NPOI.SS.Formula.Functions;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Drawing.Drawing2D;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using TSA_V.Common;
namespace TSA_V
{
public partial class FrmNImageViewer : FrmBase
{
private string fileName = "";
private bool update = false;
public FrmNImageViewer(string fileName)
{
InitializeComponent();
this.fileName = fileName;
}
private void FrmImageViewer_Load(object sender, EventArgs e)
{
if (fileName != null && File.Exists(fileName))
{
System.Drawing.Image img = System.Drawing.Image.FromFile(fileName);
Bitmap myImage = new System.Drawing.Bitmap(img);
this.picViewer.Image = myImage;
img.Dispose();
btnOK.Focus();
}
}
private void BackFile()
{
string directory = Path.GetDirectoryName(fileName);
string extension = Path.GetExtension(fileName);
string fileNameWithoutExtension = Path.GetFileNameWithoutExtension(fileName);
// 构建新文件名为原文件名后加上后缀"back"
string backStr = DateTime.Now.ToString("yyyy_MM_dd_HH_mm_ss");
string newFileName = Path.Combine(directory, fileNameWithoutExtension + $"_{backStr}back" + extension);
try
{
// 复制原图片到新文件名
File.Copy(fileName, newFileName);
LogUtil.info("备份原图片文件到:" + newFileName);
}
catch (Exception ex)
{
LogUtil.error("出现异常:" + ex.Message);
}
}
private void btnOK_Click(object sender, EventArgs e)
{
if (update)
{
//备份原图
BackFile();
Image newImage = (Image)picViewer.Image.Clone();
newImage.Save(fileName);
LogUtil.info("保存修改后的图片:" + fileName);
}
this.DialogResult = DialogResult.OK;
this.Close();
}
private void btnCancel_Click(object sender, EventArgs e)
{
this.DialogResult = DialogResult.Cancel;
this.Close();
}
private void btnR_Click(object sender, EventArgs e)
{
int v = (int)numRValue.Value;
// 旋转图片90度
RotateImage(v);
}
//private void RotateImage(float angle)
//{
// update = true;
// Image originalImage = (Image)picViewer.Image.Clone();
// // 创建一个新的 Bitmap 用于存储旋转后的图片
// Bitmap bmp = new Bitmap(originalImage.Width, originalImage.Height);
// // 设置绘图的旋转角度和中心点
// Graphics g = Graphics.FromImage(bmp);
// g.TranslateTransform((float)bmp.Width / 2, (float)bmp.Height / 2);
// g.RotateTransform(angle);
// g.TranslateTransform(-(float)bmp.Width / 2, -(float)bmp.Height / 2);
// // 绘制旋转后的图片
// g.DrawImage(originalImage, new Point(0, 0));
// g.Dispose();
// // 更新 PictureBox 中的图片
// picViewer.Image = bmp;
// // 更新旋转后的图片
// //rotatedImage = bmp;
//}
private void RotateImage(float angle)
{
update = true;
Image originalImage = (Image)picViewer.Image.Clone();
// 计算旋转后包含整个图像的最小矩形
RectangleF rotatedRect = new RectangleF(0, 0, originalImage.Width, originalImage.Height);
PointF[] points = new PointF[] { new PointF(rotatedRect.Left, rotatedRect.Top), new PointF(rotatedRect.Right, rotatedRect.Top), new PointF(rotatedRect.Left, rotatedRect.Bottom) };
Matrix matrix = new Matrix();
matrix.RotateAt(angle, new PointF(rotatedRect.Width / 2, rotatedRect.Height / 2));
matrix.TransformPoints(points);
rotatedRect = RectangleF.FromLTRB(points.Min(p => p.X), points.Min(p => p.Y), points.Max(p => p.X), points.Max(p => p.Y));
// 创建一个新的 Bitmap 用于存储旋转后的图片
Bitmap bmp = new Bitmap((int)Math.Ceiling(rotatedRect.Width), (int)Math.Ceiling(rotatedRect.Height));
// 设置绘图的旋转角度和中心点
Graphics g = Graphics.FromImage(bmp);
g.TranslateTransform(rotatedRect.Width / 2, rotatedRect.Height / 2);
g.RotateTransform(angle);
g.TranslateTransform(-originalImage.Width / 2, -originalImage.Height / 2);
// 绘制旋转后的图片
g.DrawImage(originalImage, new Point(0, 0));
g.Dispose();
// 更新 PictureBox 中的图片
picViewer.Image = bmp;
// 更新旋转后的图片
//rotatedImage = bmp;
}
/// <summary>
/// 获取单通道的掩模图片
/// </summary>
/// <param name="img"></param>
/// <param name="path"></param>
/// <returns></returns>
public Image GetRoiMask(Image img, GraphicsPath path)
{
if (path != null)
{
//5GC.Collect();
var bounds = path.GetBounds();
if (bounds.Width > 0 && bounds.Height > 0)
{
try
{
Bitmap mask = new Bitmap(img.Width, img.Height);
using (Graphics g = Graphics.FromImage(mask))
{
var br = new TextureBrush(img);
g.FillPath(br, path);
g.Dispose();
}
return mask;
}
catch (Exception ex)
{
Console.WriteLine(ex.ToString());
}
}
}
return null;
}
public Image CutImage(Image image, GraphicsPath path, bool needCut)
{
Image maskImg = GetRoiMask(image, path);
if (maskImg != null)
{
var bounds = path.GetBounds();
int resultWidth = (int)bounds.Width;
int resultHeight = (int)bounds.Height;
var srcLocation = bounds.Location;
if (!needCut)
{
//获取带原图位置的大图
resultWidth = image.Width;
resultHeight = image.Height;
srcLocation = PointF.Empty;
}
Bitmap result = new Bitmap(resultWidth, resultHeight);
var dstRect = new RectangleF(0, 0, resultWidth, resultHeight);
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);
g.Dispose();
}
result.MakeTransparent(Color.White);
return result;
}
return null;
}
private void btnCut_Click(object sender, EventArgs e)
{
try
{
if (picViewer.SelectionRegion != null&&picViewer.SelectionRegion.PointCount>0)
{
update = true;
GraphicsPath path = picViewer.SelectionRegion;
Image originalImage = (Image)picViewer.Image.Clone();
Image cutImage = CutImage(originalImage, path, true);
picViewer.Image = cutImage;
picViewer.SelectionRegion = null;
}
}
catch (Exception ex)
{
LogUtil.error(ex.ToString());
MessageBox.Show(ex.ToString());
}
}
}
}
<?xml version="1.0" encoding="utf-8"?>
<root>
<!--
Microsoft ResX Schema
Version 2.0
The primary goals of this format is to allow a simple XML format
that is mostly human readable. The generation and parsing of the
various data types are done through the TypeConverter classes
associated with the data types.
Example:
... ado.net/XML headers & schema ...
<resheader name="resmimetype">text/microsoft-resx</resheader>
<resheader name="version">2.0</resheader>
<resheader name="reader">System.Resources.ResXResourceReader, System.Windows.Forms, ...</resheader>
<resheader name="writer">System.Resources.ResXResourceWriter, System.Windows.Forms, ...</resheader>
<data name="Name1"><value>this is my long string</value><comment>this is a comment</comment></data>
<data name="Color1" type="System.Drawing.Color, System.Drawing">Blue</data>
<data name="Bitmap1" mimetype="application/x-microsoft.net.object.binary.base64">
<value>[base64 mime encoded serialized .NET Framework object]</value>
</data>
<data name="Icon1" type="System.Drawing.Icon, System.Drawing" mimetype="application/x-microsoft.net.object.bytearray.base64">
<value>[base64 mime encoded string representing a byte array form of the .NET Framework object]</value>
<comment>This is a comment</comment>
</data>
There are any number of "resheader" rows that contain simple
name/value pairs.
Each data row contains a name, and value. The row also contains a
type or mimetype. Type corresponds to a .NET class that support
text/value conversion through the TypeConverter architecture.
Classes that don't support this are serialized and stored with the
mimetype set.
The mimetype is used for serialized objects, and tells the
ResXResourceReader how to depersist the object. This is currently not
extensible. For a given mimetype the value must be set accordingly:
Note - application/x-microsoft.net.object.binary.base64 is the format
that the ResXResourceWriter will generate, however the reader can
read any of the formats listed below.
mimetype: application/x-microsoft.net.object.binary.base64
value : The object must be serialized with
: System.Runtime.Serialization.Formatters.Binary.BinaryFormatter
: and then encoded with base64 encoding.
mimetype: application/x-microsoft.net.object.soap.base64
value : The object must be serialized with
: System.Runtime.Serialization.Formatters.Soap.SoapFormatter
: and then encoded with base64 encoding.
mimetype: application/x-microsoft.net.object.bytearray.base64
value : The object must be serialized into a byte array
: using a System.ComponentModel.TypeConverter
: and then encoded with base64 encoding.
-->
<xsd:schema id="root" xmlns="" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata">
<xsd:import namespace="http://www.w3.org/XML/1998/namespace" />
<xsd:element name="root" msdata:IsDataSet="true">
<xsd:complexType>
<xsd:choice maxOccurs="unbounded">
<xsd:element name="metadata">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" />
</xsd:sequence>
<xsd:attribute name="name" use="required" type="xsd:string" />
<xsd:attribute name="type" type="xsd:string" />
<xsd:attribute name="mimetype" type="xsd:string" />
<xsd:attribute ref="xml:space" />
</xsd:complexType>
</xsd:element>
<xsd:element name="assembly">
<xsd:complexType>
<xsd:attribute name="alias" type="xsd:string" />
<xsd:attribute name="name" type="xsd:string" />
</xsd:complexType>
</xsd:element>
<xsd:element name="data">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
<xsd:element name="comment" type="xsd:string" minOccurs="0" msdata:Ordinal="2" />
</xsd:sequence>
<xsd:attribute name="name" type="xsd:string" use="required" msdata:Ordinal="1" />
<xsd:attribute name="type" type="xsd:string" msdata:Ordinal="3" />
<xsd:attribute name="mimetype" type="xsd:string" msdata:Ordinal="4" />
<xsd:attribute ref="xml:space" />
</xsd:complexType>
</xsd:element>
<xsd:element name="resheader">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
</xsd:sequence>
<xsd:attribute name="name" type="xsd:string" use="required" />
</xsd:complexType>
</xsd:element>
</xsd:choice>
</xsd:complexType>
</xsd:element>
</xsd:schema>
<resheader name="resmimetype">
<value>text/microsoft-resx</value>
</resheader>
<resheader name="version">
<value>2.0</value>
</resheader>
<resheader name="reader">
<value>System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader>
<resheader name="writer">
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader>
</root>
\ No newline at end of file \ No newline at end of file
...@@ -44,6 +44,7 @@ ...@@ -44,6 +44,7 @@
this.lblDes = new System.Windows.Forms.Label(); this.lblDes = new System.Windows.Forms.Label();
this.lblPosition = new System.Windows.Forms.Label(); this.lblPosition = new System.Windows.Forms.Label();
this.tableLayoutPanel1 = new System.Windows.Forms.TableLayoutPanel(); this.tableLayoutPanel1 = new System.Windows.Forms.TableLayoutPanel();
this.cmbPosition = new System.Windows.Forms.ComboBox();
this.txtScanPn = new System.Windows.Forms.TextBox(); this.txtScanPn = new System.Windows.Forms.TextBox();
this.label6 = new System.Windows.Forms.Label(); this.label6 = new System.Windows.Forms.Label();
((System.ComponentModel.ISupportInitialize)(this.numCount)).BeginInit(); ((System.ComponentModel.ISupportInitialize)(this.numCount)).BeginInit();
...@@ -245,9 +246,21 @@ ...@@ -245,9 +246,21 @@
this.tableLayoutPanel1.RowStyles.Add(new System.Windows.Forms.RowStyle(System.Windows.Forms.SizeType.Percent, 20F)); this.tableLayoutPanel1.RowStyles.Add(new System.Windows.Forms.RowStyle(System.Windows.Forms.SizeType.Percent, 20F));
this.tableLayoutPanel1.RowStyles.Add(new System.Windows.Forms.RowStyle(System.Windows.Forms.SizeType.Percent, 20F)); this.tableLayoutPanel1.RowStyles.Add(new System.Windows.Forms.RowStyle(System.Windows.Forms.SizeType.Percent, 20F));
this.tableLayoutPanel1.RowStyles.Add(new System.Windows.Forms.RowStyle(System.Windows.Forms.SizeType.Percent, 20F)); this.tableLayoutPanel1.RowStyles.Add(new System.Windows.Forms.RowStyle(System.Windows.Forms.SizeType.Percent, 20F));
this.tableLayoutPanel1.RowStyles.Add(new System.Windows.Forms.RowStyle(System.Windows.Forms.SizeType.Absolute, 20F));
this.tableLayoutPanel1.Size = new System.Drawing.Size(539, 300); this.tableLayoutPanel1.Size = new System.Drawing.Size(539, 300);
this.tableLayoutPanel1.TabIndex = 302; this.tableLayoutPanel1.TabIndex = 302;
// //
// cmbPosition
//
this.cmbPosition.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList;
this.cmbPosition.Font = new System.Drawing.Font("微软雅黑", 12F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(134)));
this.cmbPosition.FormattingEnabled = true;
this.cmbPosition.Location = new System.Drawing.Point(98, 328);
this.cmbPosition.Name = "cmbPosition";
this.cmbPosition.Size = new System.Drawing.Size(112, 29);
this.cmbPosition.TabIndex = 306;
this.cmbPosition.Visible = false;
//
// txtScanPn // txtScanPn
// //
this.txtScanPn.Font = new System.Drawing.Font("微软雅黑", 12F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(134))); this.txtScanPn.Font = new System.Drawing.Font("微软雅黑", 12F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(134)));
...@@ -272,6 +285,7 @@ ...@@ -272,6 +285,7 @@
this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 12F); this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 12F);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.ClientSize = new System.Drawing.Size(591, 488); this.ClientSize = new System.Drawing.Size(591, 488);
this.Controls.Add(this.cmbPosition);
this.Controls.Add(this.label6); this.Controls.Add(this.label6);
this.Controls.Add(this.txtScanPn); this.Controls.Add(this.txtScanPn);
this.Controls.Add(this.tableLayoutPanel1); this.Controls.Add(this.tableLayoutPanel1);
...@@ -309,5 +323,6 @@ ...@@ -309,5 +323,6 @@
private System.Windows.Forms.TableLayoutPanel tableLayoutPanel1; private System.Windows.Forms.TableLayoutPanel tableLayoutPanel1;
private System.Windows.Forms.TextBox txtScanPn; private System.Windows.Forms.TextBox txtScanPn;
private System.Windows.Forms.Label label6; private System.Windows.Forms.Label label6;
private System.Windows.Forms.ComboBox cmbPosition;
} }
} }
\ No newline at end of file \ No newline at end of file
支持 Markdown 格式
你添加了 0 到此讨论。请谨慎行事。
Finish editing this message first!