using System; using System.Drawing; using System.Collections; using System.Collections.Specialized; using System.ComponentModel; using System.Windows.Forms; using System.Data; using System.IO; using System.Net; using System.Text; using System.Text.RegularExpressions; using System.Xml; using System.Xml.XPath; namespace eBay_Images { /// /// Summary description for ImageResize. /// public class ImageResize : System.Windows.Forms.Form { private System.Windows.Forms.Button LoadImage; private System.Windows.Forms.OpenFileDialog openFileDialog1; private System.Windows.Forms.PictureBox PictureBox1; private System.Windows.Forms.HScrollBar CropX; private System.Windows.Forms.VScrollBar CropY; private System.Windows.Forms.VScrollBar CropHeight; private System.Windows.Forms.HScrollBar CropWidth; private System.Windows.Forms.Button UploadImage; private System.Windows.Forms.ListBox ListImages; private System.Windows.Forms.Label ListImagesLabel; private System.Windows.Forms.Button GenerateHTML; private System.Windows.Forms.Button ClearImages; private System.Windows.Forms.ToolTip ImageToolTip; private System.ComponentModel.IContainer components; public ImageResize() { // // Required for Windows Form Designer support // InitializeComponent(); } /// /// Clean up any resources being used. /// protected override void Dispose(bool disposing) { if (disposing) { if (components != null) { components.Dispose(); } } base.Dispose(disposing); } #region Windows Form Designer generated code /// /// Required method for Designer support - do not modify /// the contents of this method with the code editor. /// private void InitializeComponent() { this.components = new System.ComponentModel.Container(); System.ComponentModel.ComponentResourceManager resources = new System.ComponentModel.ComponentResourceManager(typeof(ImageResize)); this.LoadImage = new System.Windows.Forms.Button(); this.openFileDialog1 = new System.Windows.Forms.OpenFileDialog(); this.PictureBox1 = new System.Windows.Forms.PictureBox(); this.CropY = new System.Windows.Forms.VScrollBar(); this.CropHeight = new System.Windows.Forms.VScrollBar(); this.CropWidth = new System.Windows.Forms.HScrollBar(); this.CropX = new System.Windows.Forms.HScrollBar(); this.UploadImage = new System.Windows.Forms.Button(); this.ListImages = new System.Windows.Forms.ListBox(); this.ListImagesLabel = new System.Windows.Forms.Label(); this.GenerateHTML = new System.Windows.Forms.Button(); this.ClearImages = new System.Windows.Forms.Button(); this.ImageToolTip = new System.Windows.Forms.ToolTip(this.components); //((System.ComponentModel.ISupportInitialize)(this.PictureBox1)).BeginInit(); this.SuspendLayout(); // // LoadImage // this.LoadImage.Location = new System.Drawing.Point(88, 192); this.LoadImage.Name = "LoadImage"; this.LoadImage.Size = new System.Drawing.Size(104, 23); this.LoadImage.TabIndex = 0; this.LoadImage.TabStop = false; this.LoadImage.Text = "Load Image..."; this.LoadImage.Click += new System.EventHandler(this.LoadImage_Click); // // openFileDialog1 // this.openFileDialog1.DefaultExt = "jpg"; this.openFileDialog1.Filter = "JPEG Images|*.jpg"; this.openFileDialog1.Title = "Choose an Image..."; // // PictureBox1 // this.PictureBox1.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle; this.PictureBox1.Location = new System.Drawing.Point(32, 24); this.PictureBox1.Name = "PictureBox1"; this.PictureBox1.Size = new System.Drawing.Size(208, 144); this.PictureBox1.SizeMode = System.Windows.Forms.PictureBoxSizeMode.CenterImage; this.PictureBox1.TabIndex = 2; this.PictureBox1.TabStop = false; // // CropY // this.CropY.LargeChange = 1; this.CropY.Location = new System.Drawing.Point(16, 24); this.CropY.Name = "CropY"; this.CropY.Size = new System.Drawing.Size(16, 144); this.CropY.TabIndex = 1; this.CropY.Scroll += new System.Windows.Forms.ScrollEventHandler(this.CropY_Scroll); // // CropHeight // this.CropHeight.LargeChange = 1; this.CropHeight.Location = new System.Drawing.Point(240, 24); this.CropHeight.Name = "CropHeight"; this.CropHeight.Size = new System.Drawing.Size(16, 144); this.CropHeight.TabIndex = 3; this.CropHeight.Scroll += new System.Windows.Forms.ScrollEventHandler(this.CropHeight_Scroll); // // CropWidth // this.CropWidth.LargeChange = 1; this.CropWidth.Location = new System.Drawing.Point(32, 168); this.CropWidth.Name = "CropWidth"; this.CropWidth.Size = new System.Drawing.Size(208, 16); this.CropWidth.TabIndex = 4; this.CropWidth.Scroll += new System.Windows.Forms.ScrollEventHandler(this.CropWidth_Scroll); // // CropX // this.CropX.LargeChange = 1; this.CropX.Location = new System.Drawing.Point(32, 7); this.CropX.Name = "CropX"; this.CropX.Size = new System.Drawing.Size(208, 16); this.CropX.TabIndex = 2; this.CropX.Scroll += new System.Windows.Forms.ScrollEventHandler(this.CropX_Scroll); // // UploadImage // this.UploadImage.Location = new System.Drawing.Point(88, 232); this.UploadImage.Name = "UploadImage"; this.UploadImage.Size = new System.Drawing.Size(104, 23); this.UploadImage.TabIndex = 5; this.UploadImage.TabStop = false; this.UploadImage.Text = "Upload Image"; this.UploadImage.Click += new System.EventHandler(this.UploadImage_Click); // // ListImages // this.ListImages.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle; this.ListImages.Location = new System.Drawing.Point(288, 24); this.ListImages.Name = "ListImages"; this.ListImages.ScrollAlwaysVisible = true; this.ListImages.Size = new System.Drawing.Size(184, 145); this.ListImages.TabIndex = 6; this.ListImages.TabStop = false; this.ListImages.DoubleClick += new System.EventHandler(this.ListImages_DoubleClick); // // ListImagesLabel // this.ListImagesLabel.AutoSize = true; this.ListImagesLabel.BackColor = System.Drawing.Color.Transparent; this.ListImagesLabel.Location = new System.Drawing.Point(272, 8); this.ListImagesLabel.Name = "ListImagesLabel"; this.ListImagesLabel.Size = new System.Drawing.Size(78, 13); this.ListImagesLabel.TabIndex = 7; this.ListImagesLabel.Text = "Images to Use:"; // // GenerateHTML // this.GenerateHTML.Location = new System.Drawing.Point(328, 192); this.GenerateHTML.Name = "GenerateHTML"; this.GenerateHTML.Size = new System.Drawing.Size(104, 23); this.GenerateHTML.TabIndex = 8; this.GenerateHTML.TabStop = false; this.GenerateHTML.Text = "Copy Image Code"; this.GenerateHTML.Click += new System.EventHandler(this.GenerateHTML_Click); // // ClearImages // this.ClearImages.Location = new System.Drawing.Point(328, 232); this.ClearImages.Name = "ClearImages"; this.ClearImages.Size = new System.Drawing.Size(104, 23); this.ClearImages.TabIndex = 9; this.ClearImages.TabStop = false; this.ClearImages.Text = "Clear Image List"; this.ClearImages.Click += new System.EventHandler(this.ClearImages_Click); // // ImageToolTip // this.ImageToolTip.AutomaticDelay = 250; this.ImageToolTip.AutoPopDelay = 0; this.ImageToolTip.InitialDelay = 250; this.ImageToolTip.ReshowDelay = 10; // // ImageResize // this.AutoScaleBaseSize = new System.Drawing.Size(5, 13); this.ClientSize = new System.Drawing.Size(474, 255); this.Controls.Add(this.ListImages); this.Controls.Add(this.ClearImages); this.Controls.Add(this.GenerateHTML); this.Controls.Add(this.UploadImage); this.Controls.Add(this.CropWidth); this.Controls.Add(this.CropX); this.Controls.Add(this.CropHeight); this.Controls.Add(this.CropY); this.Controls.Add(this.PictureBox1); this.Controls.Add(this.LoadImage); this.Controls.Add(this.ListImagesLabel); this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.FixedSingle; this.Icon = ((System.Drawing.Icon)(resources.GetObject("$this.Icon"))); this.MaximizeBox = false; this.Name = "ImageResize"; this.Text = "eBay Images"; this.Load += new System.EventHandler(this.ImageResize_Load); //((System.ComponentModel.ISupportInitialize)(this.PictureBox1)).EndInit(); this.ResumeLayout(false); this.PerformLayout(); } #endregion /// /// The main entry point for the application. /// [STAThread] static void Main() { // HACK: MSBee/Build for 1.1 Framework: msbuild.exe /t:Rebuild /p:TargetFX1_1=true // fix non-compliant webservers ServicePointManager.Expect100Continue = false; Application.Run(new ImageResize()); } #region Global Variables // store the current image we're working on Image OriginalImage, PreviewImage; // and a global for the scaling factor double ScaleFactor = 1; // and the 'crop' rectangle - global for use in CreateCropBox Rectangle CropRect = new Rectangle(); // an arraylist to hold the thumbnail html ArrayList ThumbnailHTML = new ArrayList(); #endregion #region ImageResize_Load /// /// Form_Load Event, initialize stuff programatically /// private void ImageResize_Load(object sender, System.EventArgs e) { if (OriginalImage != null) OriginalImage.Dispose(); if (PreviewImage != null) PreviewImage.Dispose(); PictureBox1.Image = null; // TODO: see if any of this can be moved to FixGui() to simplify initialization this.CropX.Minimum = 0; this.CropX.Maximum = PictureBox1.Width; this.CropY.Minimum = 0; this.CropY.Maximum = PictureBox1.Height; this.CropWidth.Minimum = 0; this.CropWidth.Maximum = PictureBox1.Width; this.CropHeight.Minimum = 0; this.CropHeight.Maximum = PictureBox1.Height; this.CropX.Enabled = false; this.CropY.Enabled = false; this.CropWidth.Enabled = false; this.CropHeight.Enabled = false; this.UploadImage.Enabled = false; this.GenerateHTML.Enabled = false; this.ClearImages.Enabled = false; CropRect.X = CropX.Value; CropRect.Y = CropY.Value; CropRect.Width = CropWidth.Value; CropRect.Height = CropHeight.Value; } #endregion #region ScrollBar Events // idiosyncracy with scrollbars: // the actual maximum scrollable value is ScrollBar.Maximum - ScrollBar.LargeChange + 1 // therefore, we set ScrollBar.LargeChange = 1 private void CropX_Scroll(object sender, System.Windows.Forms.ScrollEventArgs e) { CropRect.X = e.NewValue; CreateCropBox(); this.ImageToolTip.SetToolTip(this.PictureBox1, "Dimensions after resize and crop: " + CalculateDimensionsAfterCropAndResize()); } private void CropY_Scroll(object sender, System.Windows.Forms.ScrollEventArgs e) { CropRect.Y = e.NewValue; CreateCropBox(); this.ImageToolTip.SetToolTip(this.PictureBox1, "Dimensions after resize and crop: " + CalculateDimensionsAfterCropAndResize()); } private void CropWidth_Scroll(object sender, System.Windows.Forms.ScrollEventArgs e) { CropRect.Width = e.NewValue; CreateCropBox(); this.ImageToolTip.SetToolTip(this.PictureBox1, "Dimensions after resize and crop: " + CalculateDimensionsAfterCropAndResize()); } private void CropHeight_Scroll(object sender, System.Windows.Forms.ScrollEventArgs e) { CropRect.Height = e.NewValue; CreateCropBox(); this.ImageToolTip.SetToolTip(this.PictureBox1, "Dimensions after resize and crop: " + CalculateDimensionsAfterCropAndResize()); } #endregion #region LoadImage_Click private void LoadImage_Click(object sender, System.EventArgs e) { if (openFileDialog1.ShowDialog() == DialogResult.OK) { if (OriginalImage != null) OriginalImage.Dispose(); if (PreviewImage != null) PreviewImage.Dispose(); if (this.PictureBox1.Image != null) PictureBox1.Image.Dispose(); // load the desired image into temporary storage OriginalImage = Image.FromFile(openFileDialog1.FileName); // find the scaling factor for the preview image ScaleFactor = FindScalingFactor(OriginalImage, PictureBox1.Width, PictureBox1.Height); // the receiving area for the preview version Rectangle dest = new Rectangle(); dest.X = 0; dest.Y = 0; dest.Width = (int)(OriginalImage.Width * ScaleFactor); dest.Height = (int)(OriginalImage.Height * ScaleFactor); // store the resized image in the PreviewImage global // for use by CreateCropBox() PreviewImage = ResizeImage(OriginalImage, dest, new Rectangle(0, 0, OriginalImage.Width, OriginalImage.Height)); // load the preview image into the picture box this.PictureBox1.Image = PreviewImage; // TODO: clean this up into FixGui()? // enable the scrollbars this.CropX.Enabled = true; this.CropY.Enabled = true; this.CropWidth.Enabled = true; this.CropHeight.Enabled = true; // manually do what the scroll events would do -- select the whole image initially CropRect.X = this.CropX.Value = this.CropX.Minimum; CropRect.Y = this.CropY.Value = this.CropY.Minimum; CropRect.Width = this.CropWidth.Value = this.CropWidth.Maximum; CropRect.Height = this.CropHeight.Value = this.CropHeight.Maximum; CreateCropBox(); this.ImageToolTip.SetToolTip(this.PictureBox1, "Dimensions after resize and crop: " + CalculateDimensionsAfterCropAndResize()); FixGui(); } } #endregion #region UploadImage_Click private void UploadImage_Click(object sender, System.EventArgs e) { WaitingGui(); Rectangle cropped = new Rectangle(CropRect.X, CropRect.Y, CropRect.Width, CropRect.Height); // normalize the cropbox to the original image pixels NormalizeCropCoords(ref cropped); // generate the cropped image Image CroppedImage = ResizeImage(OriginalImage, new Rectangle(0, 0, cropped.Width, cropped.Height), cropped); if (cropped.Width > 550) { double reScaleFactor = 550 / (double)cropped.Width; // we can reuse this ... cropped.X = 0; cropped.Y = 0; cropped.Width = (int)(cropped.Width * reScaleFactor); cropped.Height = (int)(cropped.Height * reScaleFactor); CroppedImage = ResizeImage(CroppedImage, cropped, new Rectangle(0, 0, CroppedImage.Width, CroppedImage.Height)); } // all we care about for final size constraints is the width, and that the image // itself is bigger than 200x200 if (CroppedImage.Width > 200 && CroppedImage.Height > 200) { // big try loop in case the http transaction fails string XMLResponse = String.Empty; try { // make the image a memory stream to convert to a byte array MemoryStream msCroppedImage = new MemoryStream(); // put the image into the stream CroppedImage.Save(msCroppedImage, System.Drawing.Imaging.ImageFormat.Jpeg); // byte array for the stream byte[] CroppedImageJPEG = new byte[msCroppedImage.Length]; // make sure the stream starts at the beginning msCroppedImage.Position = 0; // finally copy the stream into the byte array msCroppedImage.Read(CroppedImageJPEG, 0, (int)msCroppedImage.Length); // build form values here (pull out of HttpFileUpload, NameValueCollection) // do the upload UploadSpec FileUpload = new UploadSpec(CroppedImageJPEG, openFileDialog1.FileName, "fileupload"); StringDictionary OtherFields = new StringDictionary(); OtherFields.Add("xml", "yes"); OtherFields.Add("rembar", "1"); HttpWebResponse reply = HttpUpload.Upload( new Uri("http://www.imageshack.us/index.php"), OtherFields, null, null, FileUpload); StreamReader srReply = new StreamReader(reply.GetResponseStream()); // and save the response XMLResponse = srReply.ReadToEnd(); // setup the lists with: ThumbnailHTML.Add(GetThumbnailLink(XMLResponse)); ListImages.Items.Add(openFileDialog1.FileName.Substring(openFileDialog1.FileName.LastIndexOf(@"\") + 1)); // since we worked, lets clean up stuff this.PictureBox1.Image = null; // test the error logging //throw new ApplicationException(); } catch (Exception ex) { Boolean Logged = false; try { DateTime ErrorTime = DateTime.Now; FileInfo exe = new FileInfo(Application.ExecutablePath); DirectoryInfo AppPath = exe.Directory; FileStream LogFile = new FileStream(String.Format(@"{0}\error_{1:yyyyMMdd-HHmmss}.txt", AppPath.FullName, ErrorTime), FileMode.Create, FileAccess.Write, FileShare.Read); StreamWriter LogWriter = new StreamWriter(LogFile); LogWriter.WriteLine(ErrorTime.ToString("MM/dd/yyyy HH:mm:ss")); LogWriter.WriteLine(Environment.NewLine); LogWriter.WriteLine("Exception:"); LogWriter.WriteLine(ex.ToString()); LogWriter.WriteLine(Environment.NewLine); LogWriter.WriteLine(XMLResponse); LogWriter.Flush(); LogWriter.Close(); Logged = true; } catch { Logged = false; } MessageBox.Show(String.Format("{0}Error:{1}{2}", (Logged ? "Logged " : String.Empty), Environment.NewLine, ex.ToString()), "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); } } else { MessageBox.Show("The cropped area is too small to generate a thumbnail!\n\nIt is currently " + CalculateDimensionsAfterCropAndResize() + ", but needs to be at greater than 200x200!", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); } FixGui(); } #endregion #region GenerateHTML_Click private void GenerateHTML_Click(object sender, System.EventArgs e) { // TODO: this should probably get rewritten to be cleaner, but it gets the job done for now StringBuilder result = new StringBuilder(); int i = ThumbnailHTML.Count, j = 0; if (i > 0) { result.Append("\r\n"); if (i % 2 == 1) { result.Append("\t\r\n"); result.Append("\t\t\r\n"); result.Append("\t\r\n"); j++; } // TODO: figure out the case to add the 'tr' (modulus) and make less-icky while (j < i) { result.Append("\t\r\n"); result.Append("\t\t\r\n"); j++; result.Append("\t\t\r\n"); result.Append("\t\r\n"); j++; } result.Append("
\r\n"); result.Append("\t\t\t" + ThumbnailHTML[j] + "\r\n"); //line result.Append("\t\t
\r\n"); result.Append("\t\t\t" + ThumbnailHTML[j] + "\r\n"); //line result.Append("\t\t\r\n"); result.Append("\t\t\t" + ThumbnailHTML[j] + "\r\n"); //line result.Append("\t\t
\r\n"); Clipboard.SetDataObject(result.ToString(), true); MessageBox.Show("The thumbnail HTML has been copied to the clipboard.", "HTML Copied", MessageBoxButtons.OK, MessageBoxIcon.Information); } else { MessageBox.Show("You must add some images!", "Error!", MessageBoxButtons.OK, MessageBoxIcon.Error); } } #endregion #region ClearImages_Click private void ClearImages_Click(object sender, System.EventArgs e) { ThumbnailHTML.Clear(); this.ListImages.Items.Clear(); this.ListImagesLabel.Text = "Images to Use:"; FixGui(); } #endregion #region ListImages_DoubleClick private void ListImages_DoubleClick(object sender, EventArgs e) { // this function allows a double-click of the list to return the link to just that file if (ListImages.SelectedIndex > -1) { //line = Regex.Replace(line, ".*value=\"(.*)\".*", "$1"); string URL = Regex.Replace(ThumbnailHTML[ListImages.SelectedIndex].ToString(), ".*.*", "$1"); if (URL.Length > 0) { Clipboard.SetDataObject(URL, true); MessageBox.Show("Copied URL for " + ListImages.SelectedItem.ToString() + " to the clipboard", this.Text, MessageBoxButtons.OK, MessageBoxIcon.Information); } else { MessageBox.Show("Error parsing ThumbnailHTML", this.Text, MessageBoxButtons.OK, MessageBoxIcon.Error); } } } #endregion #region Helper Functions #region ResizeImage /// /// Resize an Image given a Rectangle to fit it into. /// /// The Image to Resize /// The Rectangle area to fit it into. /// A MemoryStream with the resized image. //private MemoryStream ResizeImage(Image ImageToResize, Rectangle Portion, int NewWidth, int NewHeight) { private Image ResizeImage(Image ImageToResize, Rectangle NewSize, Rectangle SourceArea) { // the image to return Image retval; // the stream that will contain the image returned to the caller MemoryStream ms = new MemoryStream(); // build the container for the resized image Bitmap bmp = new Bitmap(NewSize.Width, NewSize.Height); Graphics g = Graphics.FromImage(bmp); // perform a high quality bicubic resize g.InterpolationMode = System.Drawing.Drawing2D.InterpolationMode.HighQualityBicubic; g.DrawImage(ImageToResize, NewSize, SourceArea, GraphicsUnit.Pixel); // copy the image to the stream bmp.Save(ms, System.Drawing.Imaging.ImageFormat.Bmp); // and build the returned image from the stream retval = Image.FromStream(ms); // cleanup bmp.Dispose(); g.Dispose(); return retval; } #endregion #region CreateCropBox /// /// Draws the Cropping Box on the PreviewImage (non-destructively) and places that new Image in the PictureBox. /// private void CreateCropBox() { // temp image to have cropbox overlain Image WithCropBox = (Image)PreviewImage.Clone(); // bind g to that temp image Graphics g = Graphics.FromImage(WithCropBox); // add the cropping rectangle g.DrawRectangle(new Pen(Brushes.Azure, 2), CropRect); // cleanup g.Dispose(); // and output it to the picture box PictureBox1.Image = WithCropBox; } #endregion #region FindScalingFactor /// /// Calculate the scaling factor to reduce an image by to fit it into a MaxWidth x MaxHeight area. /// /// The image to scale to fit in a MaxWidth x MaxHeight area. /// Maximum width of the area to contain OriginalImage. /// Maximum height of the area to contain OriginalImage. /// The scaling factor of OriginalImage to make it fit within a MaxWidth x MaxHeight area, or 1 if it will fit. double FindScalingFactor(Image OriginalImage, int MaxWidth, int MaxHeight) { double scaleFactorWidth = 1, scaleFactorHeight = 1; if (OriginalImage.Width > MaxWidth) { scaleFactorWidth = (double)MaxWidth / (double)OriginalImage.Width; } if (OriginalImage.Height > MaxHeight) { scaleFactorHeight = (double)MaxHeight / (double)OriginalImage.Height; } // return the scale factor that will scale the image the most return Math.Min(scaleFactorWidth, scaleFactorHeight); } #endregion #region NormalizeCropCoords private void NormalizeCropCoords(ref Rectangle coords) { // normalize the cropped box to the actual image double unScaleFactor = 1 / ScaleFactor; coords.X = (int)(coords.X * unScaleFactor); coords.Y = (int)(coords.Y * unScaleFactor); coords.Width = (int)(coords.Width * unScaleFactor); coords.Height = (int)(coords.Height * unScaleFactor); // crop only parts of the image -- not beyond // -- do after the normalize to make sure if the whole image is desired we comply if (coords.X + coords.Width > OriginalImage.Width) { coords.Width = OriginalImage.Width - coords.X; } if (coords.Y + coords.Height > OriginalImage.Height) { coords.Height = OriginalImage.Height - coords.Y; } } #endregion #region CalculateDimensionsAfterCropAndResize private string CalculateDimensionsAfterCropAndResize() { Rectangle cropped = new Rectangle(CropRect.X, CropRect.Y, CropRect.Width, CropRect.Height); NormalizeCropCoords(ref cropped); if (cropped.Width > 550) { double reScaleFactor = 550 / (double)cropped.Width; // we can reuse this ... cropped.X = 0; cropped.Y = 0; cropped.Width = (int)(cropped.Width * reScaleFactor); cropped.Height = (int)(cropped.Height * reScaleFactor); } return String.Format("{0}x{1}", cropped.Width, cropped.Height); } #endregion #region GetImageLink /// /// Returns the image link, used when the list is Double-Clicked /// /// XML Returned from the server /// Image Link private string GetImageLink(string XML) { XmlDocument xmlDoc = new XmlDocument(); xmlDoc.LoadXml(XML); XmlNode ImageLink = xmlDoc.SelectSingleNode("//image_link"); if (ImageLink.Value.Length == 0) throw new ApplicationException("ImageLink has Zero Length"); return ImageLink.Value; } #endregion #region GetThumbnailLink /// /// Returns a thumbnail link based on the XML returned by the webserver. /// /// XML Returned from the server /// Thumbnail Link private string GetThumbnailLink(string XML) { // Free Image Hosting at www.ImageShack.us XmlDocument xmlDoc = new XmlDocument(); xmlDoc.LoadXml(XML); XmlNode ThumbnailExists = xmlDoc.SelectSingleNode("//thumb_exists"); if (!(ThumbnailExists.InnerText == "yes")) throw new ApplicationException("No Thumbnail Exists"); XmlNode ThumbnailLink = xmlDoc.SelectSingleNode("//thumb_link"); XmlNode ImageLink = xmlDoc.SelectSingleNode("//image_link"); if (ThumbnailLink.InnerText.Length == 0 || ImageLink.InnerText.Length == 0) throw new ApplicationException("ThumbnailLink or ImageLink has Zero Length"); return string.Format("", ImageLink.InnerText, ThumbnailLink.InnerText); } #endregion #endregion #region GUI Management #region WatingGui private void WaitingGui() { this.Cursor = Cursors.WaitCursor; this.LoadImage.Enabled = false; this.UploadImage.Enabled = false; this.GenerateHTML.Enabled = false; this.ClearImages.Enabled = false; this.CropX.Enabled = false; this.CropY.Enabled = false; this.CropWidth.Enabled = false; this.CropHeight.Enabled = false; } #endregion #region FixGui private void FixGui() { this.LoadImage.Enabled = true; if (this.PictureBox1.Image != null) { this.UploadImage.Enabled = true; } else { this.UploadImage.Enabled = false; this.CropX.Value = this.CropX.Minimum; this.CropY.Value = this.CropY.Minimum; this.CropWidth.Value = this.CropWidth.Minimum; this.CropHeight.Value = this.CropHeight.Minimum; this.CropX.Enabled = false; this.CropY.Enabled = false; this.CropWidth.Enabled = false; this.CropHeight.Enabled = false; this.ImageToolTip.RemoveAll(); } if (this.ThumbnailHTML.Count > 0) { this.GenerateHTML.Enabled = true; this.ClearImages.Enabled = true; this.ListImagesLabel.Text = String.Format("Images to Use [ {0} ] :", this.ThumbnailHTML.Count); } else { this.GenerateHTML.Enabled = false; this.ClearImages.Enabled = false; this.ListImagesLabel.Text = "Images to Use:"; } this.Cursor = Cursors.Default; } #endregion #endregion } }