From 371a079ad2297680aeb4678a28fe660006006080 Mon Sep 17 00:00:00 2001 From: syneffort Date: Thu, 29 Sep 2022 18:06:35 +0900 Subject: [PATCH] image insert, select, save --- MainApp/MainApp/AdoClient.cs | 33 ++++ .../Image_Insert_Select_Control.Designer.cs | 181 ++++++++++++++++++ .../Controls/Image_Insert_Select_Control.cs | 145 ++++++++++++++ .../Controls/Image_Insert_Select_Control.resx | 120 ++++++++++++ .../Controls/Sql_Param_Control.Designer.cs | 62 ++++++ MainApp/MainApp/Controls/Sql_Param_Control.cs | 57 ++++++ .../MainApp/Controls/Sql_Param_Control.resx | 120 ++++++++++++ MainApp/MainApp/MainApp.csproj | 29 +++ MainApp/MainApp/MainForm.cs | 10 +- MainApp/MainApp/Properties/app.manifest | 73 +++++++ MainApp/MainApp/Util.cs | 39 ++++ 11 files changed, 868 insertions(+), 1 deletion(-) create mode 100644 MainApp/MainApp/Controls/Image_Insert_Select_Control.Designer.cs create mode 100644 MainApp/MainApp/Controls/Image_Insert_Select_Control.cs create mode 100644 MainApp/MainApp/Controls/Image_Insert_Select_Control.resx create mode 100644 MainApp/MainApp/Controls/Sql_Param_Control.Designer.cs create mode 100644 MainApp/MainApp/Controls/Sql_Param_Control.cs create mode 100644 MainApp/MainApp/Controls/Sql_Param_Control.resx create mode 100644 MainApp/MainApp/Properties/app.manifest create mode 100644 MainApp/MainApp/Util.cs diff --git a/MainApp/MainApp/AdoClient.cs b/MainApp/MainApp/AdoClient.cs index b317dd6..9fa07d4 100644 --- a/MainApp/MainApp/AdoClient.cs +++ b/MainApp/MainApp/AdoClient.cs @@ -67,6 +67,24 @@ namespace MainApp } } + public DataSet Query(string paramedSql, SqlParameter[] sqlParams) + { + using (conn = new SqlConnection(connString)) + { + conn.Open(); + + SqlCommand cmd = new SqlCommand(paramedSql, conn); + cmd.Parameters.AddRange(sqlParams); + + SqlDataAdapter adapter = new SqlDataAdapter(cmd); + DataSet dataSet = new DataSet(); + adapter.Fill(dataSet); + + conn.Close(); + return dataSet; + } + } + public int NonQuery(string sql) { using (conn = new SqlConnection(connString)) @@ -77,5 +95,20 @@ namespace MainApp return cmd.ExecuteNonQuery(); } } + + public void NonQuery(string paramedSql, SqlParameter[] sqlParams) + { + using (conn = new SqlConnection(connString)) + { + conn.Open(); + + SqlCommand cmd = new SqlCommand(paramedSql, conn); + cmd.Parameters.AddRange(sqlParams); + + cmd.ExecuteNonQuery(); + + conn.Close(); + } + } } } diff --git a/MainApp/MainApp/Controls/Image_Insert_Select_Control.Designer.cs b/MainApp/MainApp/Controls/Image_Insert_Select_Control.Designer.cs new file mode 100644 index 0000000..ede390d --- /dev/null +++ b/MainApp/MainApp/Controls/Image_Insert_Select_Control.Designer.cs @@ -0,0 +1,181 @@ + +namespace MainApp.Controls +{ + partial class Image_Insert_Select_Control + { + /// + /// 필수 디자이너 변수입니다. + /// + private System.ComponentModel.IContainer components = null; + + /// + /// 사용 중인 모든 리소스를 정리합니다. + /// + /// 관리되는 리소스를 삭제해야 하면 true이고, 그렇지 않으면 false입니다. + protected override void Dispose(bool disposing) + { + if (disposing && (components != null)) + { + components.Dispose(); + } + base.Dispose(disposing); + } + + #region 구성 요소 디자이너에서 생성한 코드 + + /// + /// 디자이너 지원에 필요한 메서드입니다. + /// 이 메서드의 내용을 코드 편집기로 수정하지 마세요. + /// + private void InitializeComponent() + { + this.tableLayoutPanel1 = new System.Windows.Forms.TableLayoutPanel(); + this.pictureBox = new System.Windows.Forms.PictureBox(); + this.saveButton = new System.Windows.Forms.Button(); + this.tableLayoutPanel2 = new System.Windows.Forms.TableLayoutPanel(); + this.uploadButton = new System.Windows.Forms.Button(); + this.selectButton = new System.Windows.Forms.Button(); + this.label1 = new System.Windows.Forms.Label(); + this.indexTextbox = new System.Windows.Forms.TextBox(); + this.nameLabel = new System.Windows.Forms.Label(); + this.tableLayoutPanel1.SuspendLayout(); + ((System.ComponentModel.ISupportInitialize)(this.pictureBox)).BeginInit(); + this.tableLayoutPanel2.SuspendLayout(); + this.SuspendLayout(); + // + // tableLayoutPanel1 + // + this.tableLayoutPanel1.ColumnCount = 1; + this.tableLayoutPanel1.ColumnStyles.Add(new System.Windows.Forms.ColumnStyle(System.Windows.Forms.SizeType.Percent, 100F)); + this.tableLayoutPanel1.Controls.Add(this.pictureBox, 0, 1); + this.tableLayoutPanel1.Controls.Add(this.saveButton, 0, 0); + this.tableLayoutPanel1.Controls.Add(this.tableLayoutPanel2, 0, 2); + this.tableLayoutPanel1.Dock = System.Windows.Forms.DockStyle.Fill; + this.tableLayoutPanel1.Location = new System.Drawing.Point(0, 0); + this.tableLayoutPanel1.Name = "tableLayoutPanel1"; + this.tableLayoutPanel1.RowCount = 3; + this.tableLayoutPanel1.RowStyles.Add(new System.Windows.Forms.RowStyle(System.Windows.Forms.SizeType.Absolute, 30F)); + this.tableLayoutPanel1.RowStyles.Add(new System.Windows.Forms.RowStyle(System.Windows.Forms.SizeType.Percent, 100F)); + this.tableLayoutPanel1.RowStyles.Add(new System.Windows.Forms.RowStyle(System.Windows.Forms.SizeType.Absolute, 35F)); + this.tableLayoutPanel1.Size = new System.Drawing.Size(554, 549); + this.tableLayoutPanel1.TabIndex = 6; + // + // pictureBox + // + this.pictureBox.Dock = System.Windows.Forms.DockStyle.Fill; + this.pictureBox.Location = new System.Drawing.Point(3, 33); + this.pictureBox.Name = "pictureBox"; + this.pictureBox.Size = new System.Drawing.Size(548, 478); + this.pictureBox.TabIndex = 4; + this.pictureBox.TabStop = false; + // + // saveButton + // + this.saveButton.Anchor = System.Windows.Forms.AnchorStyles.Right; + this.saveButton.Location = new System.Drawing.Point(457, 3); + this.saveButton.Name = "saveButton"; + this.saveButton.Size = new System.Drawing.Size(94, 23); + this.saveButton.TabIndex = 2; + this.saveButton.Text = "Save"; + this.saveButton.UseVisualStyleBackColor = true; + this.saveButton.Click += new System.EventHandler(this.saveButton_Click); + // + // tableLayoutPanel2 + // + this.tableLayoutPanel2.ColumnCount = 5; + this.tableLayoutPanel2.ColumnStyles.Add(new System.Windows.Forms.ColumnStyle(System.Windows.Forms.SizeType.Percent, 100F)); + this.tableLayoutPanel2.ColumnStyles.Add(new System.Windows.Forms.ColumnStyle(System.Windows.Forms.SizeType.Absolute, 100F)); + this.tableLayoutPanel2.ColumnStyles.Add(new System.Windows.Forms.ColumnStyle(System.Windows.Forms.SizeType.Absolute, 50F)); + this.tableLayoutPanel2.ColumnStyles.Add(new System.Windows.Forms.ColumnStyle(System.Windows.Forms.SizeType.Absolute, 50F)); + this.tableLayoutPanel2.ColumnStyles.Add(new System.Windows.Forms.ColumnStyle(System.Windows.Forms.SizeType.Absolute, 100F)); + this.tableLayoutPanel2.Controls.Add(this.uploadButton, 1, 0); + this.tableLayoutPanel2.Controls.Add(this.selectButton, 4, 0); + this.tableLayoutPanel2.Controls.Add(this.label1, 2, 0); + this.tableLayoutPanel2.Controls.Add(this.indexTextbox, 3, 0); + this.tableLayoutPanel2.Controls.Add(this.nameLabel, 0, 0); + this.tableLayoutPanel2.Dock = System.Windows.Forms.DockStyle.Fill; + this.tableLayoutPanel2.Location = new System.Drawing.Point(3, 517); + this.tableLayoutPanel2.Name = "tableLayoutPanel2"; + this.tableLayoutPanel2.RowCount = 1; + this.tableLayoutPanel2.RowStyles.Add(new System.Windows.Forms.RowStyle(System.Windows.Forms.SizeType.Percent, 100F)); + this.tableLayoutPanel2.Size = new System.Drawing.Size(548, 29); + this.tableLayoutPanel2.TabIndex = 5; + // + // uploadButton + // + this.uploadButton.Dock = System.Windows.Forms.DockStyle.Fill; + this.uploadButton.Location = new System.Drawing.Point(251, 3); + this.uploadButton.Name = "uploadButton"; + this.uploadButton.Size = new System.Drawing.Size(94, 23); + this.uploadButton.TabIndex = 0; + this.uploadButton.Text = "Upload"; + this.uploadButton.UseVisualStyleBackColor = true; + this.uploadButton.Click += new System.EventHandler(this.uploadButton_Click); + // + // selectButton + // + this.selectButton.Dock = System.Windows.Forms.DockStyle.Fill; + this.selectButton.Location = new System.Drawing.Point(451, 3); + this.selectButton.Name = "selectButton"; + this.selectButton.Size = new System.Drawing.Size(94, 23); + this.selectButton.TabIndex = 2; + this.selectButton.Text = "Select"; + this.selectButton.UseVisualStyleBackColor = true; + this.selectButton.Click += new System.EventHandler(this.selectButton_Click); + // + // label1 + // + this.label1.Dock = System.Windows.Forms.DockStyle.Fill; + this.label1.Location = new System.Drawing.Point(351, 0); + this.label1.Name = "label1"; + this.label1.Size = new System.Drawing.Size(44, 29); + this.label1.TabIndex = 1; + this.label1.Text = "Index :"; + this.label1.TextAlign = System.Drawing.ContentAlignment.MiddleCenter; + // + // indexTextbox + // + this.indexTextbox.Dock = System.Windows.Forms.DockStyle.Fill; + this.indexTextbox.Location = new System.Drawing.Point(401, 3); + this.indexTextbox.Name = "indexTextbox"; + this.indexTextbox.Size = new System.Drawing.Size(44, 21); + this.indexTextbox.TabIndex = 1; + this.indexTextbox.KeyUp += new System.Windows.Forms.KeyEventHandler(this.indexTextbox_KeyUp); + // + // nameLabel + // + this.nameLabel.Anchor = System.Windows.Forms.AnchorStyles.Left; + this.nameLabel.AutoSize = true; + this.nameLabel.Location = new System.Drawing.Point(3, 8); + this.nameLabel.Name = "nameLabel"; + this.nameLabel.Size = new System.Drawing.Size(0, 12); + this.nameLabel.TabIndex = 3; + // + // Image_Insert_Select_Control + // + this.AutoScaleDimensions = new System.Drawing.SizeF(7F, 12F); + this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; + this.Controls.Add(this.tableLayoutPanel1); + this.Name = "Image_Insert_Select_Control"; + this.Size = new System.Drawing.Size(554, 549); + this.tableLayoutPanel1.ResumeLayout(false); + ((System.ComponentModel.ISupportInitialize)(this.pictureBox)).EndInit(); + this.tableLayoutPanel2.ResumeLayout(false); + this.tableLayoutPanel2.PerformLayout(); + this.ResumeLayout(false); + + } + + #endregion + + private System.Windows.Forms.TableLayoutPanel tableLayoutPanel1; + private System.Windows.Forms.PictureBox pictureBox; + private System.Windows.Forms.TableLayoutPanel tableLayoutPanel2; + private System.Windows.Forms.Button uploadButton; + private System.Windows.Forms.Button selectButton; + private System.Windows.Forms.Label label1; + private System.Windows.Forms.TextBox indexTextbox; + private System.Windows.Forms.Label nameLabel; + private System.Windows.Forms.Button saveButton; + } +} diff --git a/MainApp/MainApp/Controls/Image_Insert_Select_Control.cs b/MainApp/MainApp/Controls/Image_Insert_Select_Control.cs new file mode 100644 index 0000000..92c7522 --- /dev/null +++ b/MainApp/MainApp/Controls/Image_Insert_Select_Control.cs @@ -0,0 +1,145 @@ +using System; +using System.Collections.Generic; +using System.ComponentModel; +using System.Data; +using System.Data.SqlClient; +using System.Drawing; +using System.Drawing.Imaging; +using System.Linq; +using System.Text; +using System.Windows.Forms; + +namespace MainApp.Controls +{ + public partial class Image_Insert_Select_Control : UserControl + { + public Image_Insert_Select_Control() + { + InitializeComponent(); + + InitInstance(); + } + + private void InitInstance() + { + pictureBox.SizeMode = PictureBoxSizeMode.Zoom; + + if (!AdoClient.Instance.SetConnection("peacecloud.synology.me,21433", "Study", "study", "Study123$")) + { + MessageBox.Show("Cannot access database."); + return; + } + } + + private void uploadButton_Click(object sender, EventArgs e) + { + OpenFileDialog dlg = new OpenFileDialog(); + if (dlg.ShowDialog() != DialogResult.OK) + return; + + Image img = Image.FromFile(dlg.FileName); + pictureBox.Image = img; + + byte[] imgByteArray = Util.ImageToByteArray(img); + + string paramedSql = "INSERT INTO IMAGE (name, image, createdAt) VALUES (@name, @image, @createdAt)"; + SqlParameter[] sqlParams = new SqlParameter[3]; + + sqlParams[0] = new SqlParameter("@name", SqlDbType.NVarChar); + string name = Guid.NewGuid().ToString(); + nameLabel.Text = name; + sqlParams[0].Value = name; + + sqlParams[1] = new SqlParameter("@image", SqlDbType.VarBinary); + sqlParams[1].Value = imgByteArray; + + sqlParams[2] = new SqlParameter("@createdAt", SqlDbType.DateTime); + sqlParams[2].Value = DateTime.Now; + + AdoClient.Instance.NonQuery(paramedSql, sqlParams); + + GC.Collect(); + } + + private void selectButton_Click(object sender, EventArgs e) + { + int idx = -1; + if (!int.TryParse(indexTextbox.Text, out idx)) + { + MessageBox.Show("Invalid index"); + return; + } + + DataSet dataSet = AdoClient.Instance.Query($"SELECT * FROM IMAGE WHERE idx = {idx}"); + if (dataSet == null || + dataSet.Tables == null || dataSet.Tables.Count < 1 || + dataSet.Tables[0].Rows == null || dataSet.Tables[0].Rows.Count < 1 || + dataSet.Tables[0].Rows[0].ItemArray == null) + { + MessageBox.Show("No matched data"); + return; + } + + object[] selectedObj = dataSet.Tables[0].Rows[0].ItemArray; + + string name = (string)selectedObj[1]; + DateTime createdAt = (DateTime)selectedObj[3]; + nameLabel.Text = $"{name}@[{createdAt.ToString("yyyy-MM-dd HH:mm:ss")}]"; + + byte[] imgByteArray = (byte[])selectedObj[2]; + + Image img = Util.ByteToImage(imgByteArray); + pictureBox.Image = img; + + GC.Collect(); + } + + private void saveButton_Click(object sender, EventArgs e) + { + if (pictureBox.Image == null) + { + MessageBox.Show("No Image to save"); + return; + } + + SaveFileDialog dlg = new SaveFileDialog(); + dlg.Filter = "png type|*.png|bmp type|*.bmp|jpg type|*.jpg"; + if (dlg.ShowDialog() != DialogResult.OK) + return; + + ImageFormat imageFormat = null; + switch (dlg.FilterIndex) + { + case 1: + imageFormat = ImageFormat.Png; + break; + case 2: + imageFormat = ImageFormat.Bmp; + break; + case 3: + imageFormat = ImageFormat.Jpeg; + break; + default: + MessageBox.Show("Invalid Type"); + break; + } + + if (imageFormat == null) + { + return; + } + + Util.SaveImage(dlg.FileName, pictureBox.Image, imageFormat); + + GC.Collect(); + } + + private void indexTextbox_KeyUp(object sender, KeyEventArgs e) + { + if (e.KeyCode != Keys.Enter) + return; + + selectButton_Click(sender, e); + } + } +} diff --git a/MainApp/MainApp/Controls/Image_Insert_Select_Control.resx b/MainApp/MainApp/Controls/Image_Insert_Select_Control.resx new file mode 100644 index 0000000..1af7de1 --- /dev/null +++ b/MainApp/MainApp/Controls/Image_Insert_Select_Control.resx @@ -0,0 +1,120 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + text/microsoft-resx + + + 2.0 + + + System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + \ No newline at end of file diff --git a/MainApp/MainApp/Controls/Sql_Param_Control.Designer.cs b/MainApp/MainApp/Controls/Sql_Param_Control.Designer.cs new file mode 100644 index 0000000..cc939b8 --- /dev/null +++ b/MainApp/MainApp/Controls/Sql_Param_Control.Designer.cs @@ -0,0 +1,62 @@ + +namespace MainApp.Controls +{ + partial class Sql_Param_Control + { + /// + /// 필수 디자이너 변수입니다. + /// + private System.ComponentModel.IContainer components = null; + + /// + /// 사용 중인 모든 리소스를 정리합니다. + /// + /// 관리되는 리소스를 삭제해야 하면 true이고, 그렇지 않으면 false입니다. + protected override void Dispose(bool disposing) + { + if (disposing && (components != null)) + { + components.Dispose(); + } + base.Dispose(disposing); + } + + #region 구성 요소 디자이너에서 생성한 코드 + + /// + /// 디자이너 지원에 필요한 메서드입니다. + /// 이 메서드의 내용을 코드 편집기로 수정하지 마세요. + /// + private void InitializeComponent() + { + this.mainGridView = new System.Windows.Forms.DataGridView(); + ((System.ComponentModel.ISupportInitialize)(this.mainGridView)).BeginInit(); + this.SuspendLayout(); + // + // mainGridView + // + this.mainGridView.ColumnHeadersHeightSizeMode = System.Windows.Forms.DataGridViewColumnHeadersHeightSizeMode.AutoSize; + this.mainGridView.Dock = System.Windows.Forms.DockStyle.Fill; + this.mainGridView.Location = new System.Drawing.Point(0, 0); + this.mainGridView.Name = "mainGridView"; + this.mainGridView.RowTemplate.Height = 23; + this.mainGridView.Size = new System.Drawing.Size(282, 237); + this.mainGridView.TabIndex = 3; + // + // Sql_Param_Control + // + this.AutoScaleDimensions = new System.Drawing.SizeF(7F, 12F); + this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; + this.Controls.Add(this.mainGridView); + this.Name = "Sql_Param_Control"; + this.Size = new System.Drawing.Size(282, 237); + ((System.ComponentModel.ISupportInitialize)(this.mainGridView)).EndInit(); + this.ResumeLayout(false); + + } + + #endregion + + private System.Windows.Forms.DataGridView mainGridView; + } +} diff --git a/MainApp/MainApp/Controls/Sql_Param_Control.cs b/MainApp/MainApp/Controls/Sql_Param_Control.cs new file mode 100644 index 0000000..ee4f45e --- /dev/null +++ b/MainApp/MainApp/Controls/Sql_Param_Control.cs @@ -0,0 +1,57 @@ +using System; +using System.Collections.Generic; +using System.ComponentModel; +using System.Data; +using System.Data.SqlClient; +using System.Drawing; +using System.Linq; +using System.Text; +using System.Windows.Forms; + +namespace MainApp.Controls +{ + public partial class Sql_Param_Control : UserControl + { + public Sql_Param_Control(string job, DateTime hiredate) + { + InitializeComponent(); + + InitInstance(job, hiredate); + } + + private void InitInstance(string job, DateTime hiredate) + { + if (!AdoClient.Instance.SetConnection("peacecloud.synology.me,21433", "Study", "study", "Study123$")) + { + MessageBox.Show("Cannot access database."); + return; + } + + DoWork(job, hiredate); + } + + private void BindTableToGridView(DataTable table) + { + mainGridView.SuspendLayout(); + mainGridView.DataSource = table; + mainGridView.AutoSizeColumnsMode = DataGridViewAutoSizeColumnsMode.AllCells; + mainGridView.ResumeLayout(); + } + + private void DoWork(string job, DateTime hiredate) + { + string paramedSql = "SELECT * FROM EMPLOYEE WHERE JOB = @job AND HIREDATE >= @hiredate"; + SqlParameter[] sqlParams = new SqlParameter[] + { + new SqlParameter("@job", SqlDbType.VarChar), + new SqlParameter("@hiredate", SqlDbType.Date) + }; + sqlParams[0].Value = job; + sqlParams[1].Value = hiredate; + + + DataSet dataSet = AdoClient.Instance.Query(paramedSql, sqlParams); + BindTableToGridView(dataSet.Tables[0]); + } + } +} diff --git a/MainApp/MainApp/Controls/Sql_Param_Control.resx b/MainApp/MainApp/Controls/Sql_Param_Control.resx new file mode 100644 index 0000000..1af7de1 --- /dev/null +++ b/MainApp/MainApp/Controls/Sql_Param_Control.resx @@ -0,0 +1,120 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + text/microsoft-resx + + + 2.0 + + + System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + \ No newline at end of file diff --git a/MainApp/MainApp/MainApp.csproj b/MainApp/MainApp/MainApp.csproj index 6cf4a27..f9711e5 100644 --- a/MainApp/MainApp/MainApp.csproj +++ b/MainApp/MainApp/MainApp.csproj @@ -31,6 +31,15 @@ prompt 4 + + LocalIntranet + + + false + + + Properties\app.manifest + @@ -46,6 +55,12 @@ + + UserControl + + + Image_Insert_Select_Control.cs + UserControl @@ -64,6 +79,12 @@ Multiple_Query_Control.cs + + UserControl + + + Sql_Param_Control.cs + Form @@ -72,6 +93,10 @@ + + + Image_Insert_Select_Control.cs + Insert_Select_Control.cs @@ -81,6 +106,9 @@ Multiple_Query_Control.cs + + Sql_Param_Control.cs + MainForm.cs @@ -93,6 +121,7 @@ True Resources.resx + SettingsSingleFileGenerator Settings.Designer.cs diff --git a/MainApp/MainApp/MainForm.cs b/MainApp/MainApp/MainForm.cs index 1fadbb6..b907523 100644 --- a/MainApp/MainApp/MainForm.cs +++ b/MainApp/MainApp/MainForm.cs @@ -38,7 +38,15 @@ namespace MainApp //control.Dock = DockStyle.Fill; //this.Controls.Add(control); - Multiple_Query_Control control = new Multiple_Query_Control(); + //Multiple_Query_Control control = new Multiple_Query_Control(); + //control.Dock = DockStyle.Fill; + //this.Controls.Add(control); + + //Sql_Param_Control control = new Sql_Param_Control("tester", DateTime.Now.AddDays(-1)); + //control.Dock = DockStyle.Fill; + //this.Controls.Add(control); + + Image_Insert_Select_Control control = new Image_Insert_Select_Control(); control.Dock = DockStyle.Fill; this.Controls.Add(control); } diff --git a/MainApp/MainApp/Properties/app.manifest b/MainApp/MainApp/Properties/app.manifest new file mode 100644 index 0000000..6d3988c --- /dev/null +++ b/MainApp/MainApp/Properties/app.manifest @@ -0,0 +1,73 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/MainApp/MainApp/Util.cs b/MainApp/MainApp/Util.cs new file mode 100644 index 0000000..3d9402b --- /dev/null +++ b/MainApp/MainApp/Util.cs @@ -0,0 +1,39 @@ +using System; +using System.Collections.Generic; +using System.Drawing; +using System.Drawing.Imaging; +using System.IO; +using System.Linq; +using System.Text; + +namespace MainApp +{ + class Util + { + public static byte[] ImageToByteArray(Image image) + { + using (MemoryStream ms = new MemoryStream()) + { + image.Save(ms, image.RawFormat); + return ms.ToArray(); + } + } + + public static Bitmap ByteToImage(byte[] imgByteArray) + { + using (MemoryStream ms = new MemoryStream(imgByteArray)) + { + Bitmap img = Image.FromStream(ms) as Bitmap; + return img; + } + } + + public static void SaveImage(string fileName, Image img, ImageFormat format) + { + using (Image saveImage = new Bitmap(img)) + { + saveImage.Save(fileName, format); + } + } + } +}