diff --git a/Programs/GridImageUpload/frmGridImageUpload.Designer.cs b/Programs/GridImageUpload/frmGridImageUpload.Designer.cs index f3c0bbb3..b2750e27 100644 --- a/Programs/GridImageUpload/frmGridImageUpload.Designer.cs +++ b/Programs/GridImageUpload/frmGridImageUpload.Designer.cs @@ -49,6 +49,7 @@ namespace GridImageUpload this.label6 = new System.Windows.Forms.Label(); this.chkLossless = new System.Windows.Forms.CheckBox(); this.cmdUpload = new System.Windows.Forms.Button(); + this.cmdSave = new System.Windows.Forms.Button(); this.grpLogin.SuspendLayout(); this.grpUpload.SuspendLayout(); ((System.ComponentModel.ISupportInitialize)(this.picPreview)).BeginInit(); @@ -144,6 +145,7 @@ namespace GridImageUpload // // grpUpload // + this.grpUpload.Controls.Add(this.cmdSave); this.grpUpload.Controls.Add(this.txtAssetID); this.grpUpload.Controls.Add(this.label4); this.grpUpload.Controls.Add(this.lblSize); @@ -166,7 +168,7 @@ namespace GridImageUpload this.txtAssetID.Name = "txtAssetID"; this.txtAssetID.ReadOnly = true; this.txtAssetID.Size = new System.Drawing.Size(280, 20); - this.txtAssetID.TabIndex = 9; + this.txtAssetID.TabIndex = 10; this.txtAssetID.TabStop = false; // // label4 @@ -204,9 +206,9 @@ namespace GridImageUpload // // cmdLoad // - this.cmdLoad.Location = new System.Drawing.Point(160, 136); + this.cmdLoad.Location = new System.Drawing.Point(86, 136); this.cmdLoad.Name = "cmdLoad"; - this.cmdLoad.Size = new System.Drawing.Size(102, 24); + this.cmdLoad.Size = new System.Drawing.Size(91, 24); this.cmdLoad.TabIndex = 7; this.cmdLoad.Text = "Load Texture"; this.cmdLoad.UseVisualStyleBackColor = true; @@ -242,14 +244,25 @@ namespace GridImageUpload // cmdUpload // this.cmdUpload.Enabled = false; - this.cmdUpload.Location = new System.Drawing.Point(268, 136); + this.cmdUpload.Location = new System.Drawing.Point(280, 136); this.cmdUpload.Name = "cmdUpload"; - this.cmdUpload.Size = new System.Drawing.Size(103, 24); - this.cmdUpload.TabIndex = 8; + this.cmdUpload.Size = new System.Drawing.Size(91, 24); + this.cmdUpload.TabIndex = 9; this.cmdUpload.Text = "Upload Texture"; this.cmdUpload.UseVisualStyleBackColor = true; this.cmdUpload.Click += new System.EventHandler(this.cmdUpload_Click); // + // cmdSave + // + this.cmdSave.Enabled = false; + this.cmdSave.Location = new System.Drawing.Point(183, 136); + this.cmdSave.Name = "cmdSave"; + this.cmdSave.Size = new System.Drawing.Size(91, 24); + this.cmdSave.TabIndex = 8; + this.cmdSave.Text = "Save Texture"; + this.cmdSave.UseVisualStyleBackColor = true; + this.cmdSave.Click += new System.EventHandler(this.cmdSave_Click); + // // frmGridImageUpload // this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F); @@ -295,6 +308,7 @@ namespace GridImageUpload private System.Windows.Forms.Label label4; private System.Windows.Forms.ComboBox cboLoginURL; private System.Windows.Forms.Label label5; + private System.Windows.Forms.Button cmdSave; } } diff --git a/Programs/GridImageUpload/frmGridImageUpload.cs b/Programs/GridImageUpload/frmGridImageUpload.cs index 75bf3ee8..fd1331d7 100644 --- a/Programs/GridImageUpload/frmGridImageUpload.cs +++ b/Programs/GridImageUpload/frmGridImageUpload.cs @@ -84,15 +84,15 @@ namespace GridImageUpload private void LoadImage() { - if (FileName == null || FileName == "") + if (String.IsNullOrEmpty(FileName)) return; - string lowfilename = FileName.ToLower(); + string extension = System.IO.Path.GetExtension(FileName).ToLower(); Bitmap bitmap = null; try { - if (lowfilename.EndsWith(".jp2") || lowfilename.EndsWith(".j2c")) + if (extension == ".jp2" || extension == ".j2c") { Image image; ManagedImage managedImage; @@ -107,7 +107,7 @@ namespace GridImageUpload } else { - if (lowfilename.EndsWith(".tga")) + if (extension == ".tga") bitmap = LoadTGAClass.LoadTGA(FileName); else bitmap = (Bitmap)System.Drawing.Image.FromFile(FileName); @@ -170,6 +170,7 @@ namespace GridImageUpload catch (Exception ex) { UploadData = null; + cmdSave.Enabled = false; cmdUpload.Enabled = false; MessageBox.Show(ex.ToString(), "SL Image Upload", MessageBoxButtons.OK, MessageBoxIcon.Error); return; @@ -178,9 +179,35 @@ namespace GridImageUpload picPreview.Image = bitmap; lblSize.Text = Math.Round((double)UploadData.Length / 1024.0d, 2) + "KB"; prgUpload.Maximum = UploadData.Length; + + cmdSave.Enabled = true; if (Client.Network.Connected) cmdUpload.Enabled = true; } + private void SaveImage() + { + if (String.IsNullOrEmpty(FileName)) + return; + + if (UploadData != null) + { + try + { + System.IO.File.WriteAllBytes(FileName, UploadData); + MessageBox.Show("Saved " + UploadData.Length + " bytes to " + FileName); + } + catch (Exception ex) + { + MessageBox.Show("Failed to save " + FileName + ": " + ex.Message, Application.ProductName, + MessageBoxButtons.OK, MessageBoxIcon.Exclamation); + } + } + else + { + MessageBox.Show("No image data loaded", Application.ProductName, MessageBoxButtons.OK, MessageBoxIcon.Exclamation); + } + } + private void cmdConnect_Click(object sender, EventArgs e) { if (cmdConnect.Text == "Connect") @@ -250,6 +277,18 @@ namespace GridImageUpload } } + private void cmdSave_Click(object sender, EventArgs e) + { + SaveFileDialog dialog = new SaveFileDialog(); + dialog.Filter = "JPEG2000 File (*.j2c)|*.j2c;"; + + if (dialog.ShowDialog() == DialogResult.OK) + { + FileName = dialog.FileName; + SaveImage(); + } + } + private void cmdUpload_Click(object sender, EventArgs e) { SendToID = UUID.Zero; @@ -297,6 +336,7 @@ namespace GridImageUpload { prgUpload.Value = 0; cmdLoad.Enabled = false; + cmdSave.Enabled = false; cmdUpload.Enabled = false; grpLogin.Enabled = false; @@ -372,6 +412,7 @@ namespace GridImageUpload private void EnableControls() { cmdLoad.Enabled = true; + cmdSave.Enabled = true; cmdUpload.Enabled = true; grpLogin.Enabled = true; }