Udostępnij za pośrednictwem


Get Image Metadata (Part 2)

Continuing from the  “Get Image Metadata (Part 1)” blog posting, we should now have the first part of the code Written which will send the captured image the Microsoft Cognitive Services Vision API. In this next section we will build the Image collection piece with a user friendly UI as well as create a new class.

1st lets create the additional class

In the Solution Explorer Right Click on the Project Name in this example its “GetImageMetaData” and select Add Class

In the Add new class window , Name the class “AnalysisResults”

Click on Add

Now you should see a new class added to your code that has the following code within it…

In between the braces of

class AnalysisResults
{

}

Change class AnalysisResults to public class AnalysisResults

Than add the following 2 lines of code in-between the 2 Braces of the public class AnalysisResults

public dynamic JsonObj;
public string jsonStr;

The code in the class should now look like …

 

 

I know its not much to it but lets just continue shall we.

now we could create the text boxes manually and define actions to the text boxes for the User Interface , but that will be for another blog. To speed things up we will just add the needed code to set up the interface.

In the Solution Explorer Double click on  “Form1.Designer.cs” which is under the “Form1.cs”

After the brace of

private void InitializeComponent()
{

NOTE : remove the existing code after the brace and replace with the following code.

this.label1 = new System.Windows.Forms.Label();
this.txtPicFilename = new System.Windows.Forms.TextBox();
this.cmdBrowse = new System.Windows.Forms.Button();
this.cmdAnalyze = new System.Windows.Forms.Button();
this.label2 = new System.Windows.Forms.Label();
this.txtResults = new System.Windows.Forms.TextBox();
this.txtDescription = new System.Windows.Forms.TextBox();
this.SuspendLayout();
//
// label1
//
this.label1.AutoSize = true;
this.label1.Location = new System.Drawing.Point(23, 23);
this.label1.Name = "label1";
this.label1.Size = new System.Drawing.Size(157, 25);
this.label1.TabIndex = 0;
this.label1.Text = "Picture Filename";
//
// txtPicFilename
//
this.txtPicFilename.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Left)
| System.Windows.Forms.AnchorStyles.Right)));
this.txtPicFilename.Location = new System.Drawing.Point(28, 52);
this.txtPicFilename.Name = "txtPicFilename";
this.txtPicFilename.Size = new System.Drawing.Size(818, 29);
this.txtPicFilename.TabIndex = 1;
//
// cmdBrowse
//
this.cmdBrowse.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Right)));
this.cmdBrowse.Location = new System.Drawing.Point(863, 45);
this.cmdBrowse.Name = "cmdBrowse";
this.cmdBrowse.Size = new System.Drawing.Size(65, 45);
this.cmdBrowse.TabIndex = 2;
this.cmdBrowse.Text = "...";
this.cmdBrowse.UseVisualStyleBackColor = true;
this.cmdBrowse.Click += new System.EventHandler(this.cmdBrowse_Click);
//
// cmdAnalyze
//
this.cmdAnalyze.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Right)));
this.cmdAnalyze.Location = new System.Drawing.Point(946, 45);
this.cmdAnalyze.Name = "cmdAnalyze";
this.cmdAnalyze.Size = new System.Drawing.Size(185, 45);
this.cmdAnalyze.TabIndex = 4;
this.cmdAnalyze.Text = "Analyze";
this.cmdAnalyze.UseVisualStyleBackColor = true;
this.cmdAnalyze.Click += new System.EventHandler(this.cmdAnalyze_Click);
//
// label2
//
this.label2.AutoSize = true;
this.label2.Location = new System.Drawing.Point(23, 115);
this.label2.Name = "label2";
this.label2.Size = new System.Drawing.Size(76, 25);
this.label2.TabIndex = 5;
this.label2.Text = "Results";
//
// txtResults
//
this.txtResults.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.txtResults.Location = new System.Drawing.Point(28, 183);
this.txtResults.Multiline = true;
this.txtResults.Name = "txtResults";
this.txtResults.ScrollBars = System.Windows.Forms.ScrollBars.Vertical;
this.txtResults.Size = new System.Drawing.Size(1103, 520);
this.txtResults.TabIndex = 6;
//
// txtDescription
//
this.txtDescription.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Left)
| System.Windows.Forms.AnchorStyles.Right)));
this.txtDescription.Location = new System.Drawing.Point(28, 143);
this.txtDescription.Name = "txtDescription";
this.txtDescription.ReadOnly = true;
this.txtDescription.Size = new System.Drawing.Size(1095, 29);
this.txtDescription.TabIndex = 7;
//
// Form1
//
this.AutoScaleDimensions = new System.Drawing.SizeF(11F, 24F);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.ClientSize = new System.Drawing.Size(1161, 735);
this.Controls.Add(this.txtDescription);
this.Controls.Add(this.txtResults);
this.Controls.Add(this.label2);
this.Controls.Add(this.cmdAnalyze);
this.Controls.Add(this.cmdBrowse);
this.Controls.Add(this.txtPicFilename);
this.Controls.Add(this.label1);
this.Name = "Form1";
this.Text = "getMetadata v1.0";
this.ResumeLayout(false);
this.PerformLayout();

That complete block of code should now look like …

after the #endregion

private System.Windows.Forms.Label label1;
private System.Windows.Forms.TextBox txtPicFilename;
private System.Windows.Forms.Button cmdBrowse;
private System.Windows.Forms.Button cmdAnalyze;
private System.Windows.Forms.Label label2;
private System.Windows.Forms.TextBox txtResults;
private System.Windows.Forms.TextBox txtDescription;

That should look like..

so the final code should look like …

namespace GetImageMetaData
{
partial class Form1
{
/// <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.label1 = new System.Windows.Forms.Label();
this.txtPicFilename = new System.Windows.Forms.TextBox();
this.cmdBrowse = new System.Windows.Forms.Button();
this.cmdAnalyze = new System.Windows.Forms.Button();
this.label2 = new System.Windows.Forms.Label();
this.txtResults = new System.Windows.Forms.TextBox();
this.txtDescription = new System.Windows.Forms.TextBox();
this.SuspendLayout();
//
// label1
//
this.label1.AutoSize = true;
this.label1.Location = new System.Drawing.Point(23, 23);
this.label1.Name = "label1";
this.label1.Size = new System.Drawing.Size(157, 25);
this.label1.TabIndex = 0;
this.label1.Text = "Picture Filename";
//
// txtPicFilename
//
this.txtPicFilename.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Left)
| System.Windows.Forms.AnchorStyles.Right)));
this.txtPicFilename.Location = new System.Drawing.Point(28, 52);
this.txtPicFilename.Name = "txtPicFilename";
this.txtPicFilename.Size = new System.Drawing.Size(818, 29);
this.txtPicFilename.TabIndex = 1;
//
// cmdBrowse
//
this.cmdBrowse.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Right)));
this.cmdBrowse.Location = new System.Drawing.Point(863, 45);
this.cmdBrowse.Name = "cmdBrowse";
this.cmdBrowse.Size = new System.Drawing.Size(65, 45);
this.cmdBrowse.TabIndex = 2;
this.cmdBrowse.Text = "...";
this.cmdBrowse.UseVisualStyleBackColor = true;
this.cmdBrowse.Click += new System.EventHandler(this.cmdBrowse_Click);
//
// cmdAnalyze
//
this.cmdAnalyze.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Right)));
this.cmdAnalyze.Location = new System.Drawing.Point(946, 45);
this.cmdAnalyze.Name = "cmdAnalyze";
this.cmdAnalyze.Size = new System.Drawing.Size(185, 45);
this.cmdAnalyze.TabIndex = 4;
this.cmdAnalyze.Text = "Analyze";
this.cmdAnalyze.UseVisualStyleBackColor = true;
this.cmdAnalyze.Click += new System.EventHandler(this.cmdAnalyze_Click);
//
// label2
//
this.label2.AutoSize = true;
this.label2.Location = new System.Drawing.Point(23, 115);
this.label2.Name = "label2";
this.label2.Size = new System.Drawing.Size(76, 25);
this.label2.TabIndex = 5;
this.label2.Text = "Results";
//
// txtResults
//
this.txtResults.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.txtResults.Location = new System.Drawing.Point(28, 183);
this.txtResults.Multiline = true;
this.txtResults.Name = "txtResults";
this.txtResults.ScrollBars = System.Windows.Forms.ScrollBars.Vertical;
this.txtResults.Size = new System.Drawing.Size(1103, 520);
this.txtResults.TabIndex = 6;
//
// txtDescription
//
this.txtDescription.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Left)
| System.Windows.Forms.AnchorStyles.Right)));
this.txtDescription.Location = new System.Drawing.Point(28, 143);
this.txtDescription.Name = "txtDescription";
this.txtDescription.ReadOnly = true;
this.txtDescription.Size = new System.Drawing.Size(1095, 29);
this.txtDescription.TabIndex = 7;
//
// Form1
//
this.AutoScaleDimensions = new System.Drawing.SizeF(11F, 24F);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.ClientSize = new System.Drawing.Size(1161, 735);
this.Controls.Add(this.txtDescription);
this.Controls.Add(this.txtResults);
this.Controls.Add(this.label2);
this.Controls.Add(this.cmdAnalyze);
this.Controls.Add(this.cmdBrowse);
this.Controls.Add(this.txtPicFilename);
this.Controls.Add(this.label1);
this.Name = "Form1";
this.Text = "getMetadata v1.0";
this.ResumeLayout(false);
this.PerformLayout();

}

#endregion

private System.Windows.Forms.Label label1;
private System.Windows.Forms.TextBox txtPicFilename;
private System.Windows.Forms.Button cmdBrowse;
private System.Windows.Forms.Button cmdAnalyze;
private System.Windows.Forms.Label label2;
private System.Windows.Forms.TextBox txtResults;
private System.Windows.Forms.TextBox txtDescription;
}
}

Continue to Get Image Metadata (Part 3) Where we will Build Compile and Test