/// <summary> /// event is fired when On Text Changed /// </summary> public void OnTextChanged(Control sender, string text) { // if this is the NumberSlicesControl if (sender.Name == NumberSlicesControl.Name) { // Set the NumberSlices this.NumberSlices = NumberSlicesControl.IntValue; } else { // if this is the SliceImageControl if (sender.Name == SliceImageControl.Name) { // Store the property SliceImagePath = text; // Load the Slice this.SliceImageViewer.BackgroundImage = Image.FromFile(text); // load the pixelDatabase of the slice image this.SliceDatabase = PixelDatabaseLoader.LoadPixelDatabase(SliceImageControl.Text, this.Callback); } else if (sender.Name == TargetImageControl.Name) { // createa a fileInfo FileInfo fileInfo = new FileInfo(text); // Get the output path OutputPath = fileInfo.Directory.FullName; // create a shuffler LargeNumberShuffler shuffler = new LargeNumberShuffler(6, 1, 100000, DataJuggler.RandomShuffler.Enumerations.NumberOutOfRangeOptionEnum.ReturnModulus); // remove the extension add the random number put the extension back string name = fileInfo.Name.Replace(fileInfo.Extension, "") + shuffler.PullNumber() + fileInfo.Extension; // set the Text this.NewFileNameControl.Text = name; // Set the property TargetImagePath = text; // Load the Target TargetImageViewer.BackgroundImage = Image.FromFile(text); // load the pixelDatabase of the target image this.TargetDatabase = PixelDatabaseLoader.LoadPixelDatabase(TargetImageControl.Text, this.Callback); } // if both databases exist if ((HasSliceDatabase) && (HasTargetDatabase)) { double slices = targetDatabase.Height / sliceDatabase.Height; this.NumberSlicesControl.Text = Math.Floor(slices).ToString(); } } }
/// <summary> /// event is fired when On Text Changed /// </summary> public void OnTextChanged(Control sender, string text) { try { if (sender.Name == this.SourceImageControl.Name) { // Load the PixelDatabase this.PixelDatabase = PixelDatabaseLoader.LoadPixelDatabase(text, Refresh); // if the value for HasPixelDatabase is true if (HasPixelDatabase) { // display the height and width this.ImageHeightControl.Text = PixelDatabase.Height.ToString(); this.ImageWidthControl.Text = PixelDatabase.Width.ToString(); // Display the name as a helper FileInfo fileInfo = new FileInfo(text); this.ImageNameControl.Text = fileInfo.Name; } } else if (sender.Name == this.WidthControl.Name) { if (HasPixelDatabase) { // get the rows double rows = PixelDatabase.Width / WidthControl.IntValue; // Display the rows this.RowsControl.Text = this.Text = Math.Floor(rows).ToString(); } } else if (sender.Name == this.HeightControl.Name) { // if the value for HasPixelDatabase is true if (HasPixelDatabase) { // get the columns double columns = PixelDatabase.Height / HeightControl.IntValue; // Display the columns this.ColumnsControl.Text = this.Text = Math.Floor(columns).ToString(); } } } catch (Exception error) { // for debugging only for now DebugHelper.WriteDebugError("OnTextChanged", this.Name, error); } // Show or hide controls UIEnable(); }
/// <summary> /// This method Loads the Pixel Database /// </summary> public void LoadPixelDatabase() { // if we do not have a BackgroundImage yet if (this.Canvas.BackgroundImage == null) { // to do: Show message // bail return; } // Set to true this.Analyzing = true; // Reset the Graph this.Graph.Visible = true; this.Graph.Value = 0; // Enable or disable controls UIEnable(); // Load the PixelDatabase this.PixelDatabase = PixelDatabaseLoader.LoadPixelDatabase(this.Canvas.BackgroundImage, StatusUpdate); // Set to False this.Analyzing = false; // Set the value for the property 'ImageLoaded' to true this.ImageLoaded = true; // display the layers // LayersControl.DisplayLayers(); // Enable controls now that we are done analyzing UIEnable(); }
/// <summary> /// event is fired when the 'RandomizeButton' is clicked. /// </summary> private void RandomizeButton_Click(object sender, EventArgs e) { // setup our images string sliceImage = SliceImageControl.Text; string targetImage = TargetImageControl.Text; int rowHeight = 0; int rowWidth = 0; bool isValid = false; int offSetX = 0; int offSetY = 0; int increment = 0; int incrementedValue = 0; // load the target database PixelDatabase targetDatabase = PixelDatabaseLoader.LoadPixelDatabase(targetImage, this.Callback); // verify both objects exist if (NullHelper.Exists(sliceDatabase, targetDatabase)) { // Set the height and width rowHeight = sliceDatabase.Height; rowWidth = sliceDatabase.Width; int min = MinValueControl.IntValue; int max = MaxValueControl.IntValue; int startX = StartXControl.IntValue; int startY = StartYControl.IntValue; increment = IncrementControl.IntValue; int indent = 0; LargeNumberShuffler shuffler = null; // verify everything is in rage if ((min > 0) && (max > 0) && (max > min) || (max == 0)) { // valid isValid = true; // setup the ProgressBar this.Graph.Visible = true; this.Graph.Minimum = 0; this.Graph.Maximum = NumberSlicesControl.IntValue; // If the value for max is greater than zero if (max > 0) { // Create a new instance of a 'RandomShuffler' object. shuffler = new LargeNumberShuffler(6, 1, 375894, NumberOutOfRangeOptionEnum.ReturnModulus); } // setup the section for (int section = 0; section < NumberSlices; section++) { // Update the graph Graph.Value = section; // Add the increment to the incrementedValue incrementedValue += increment; // if max is set, else we do not need indent if (max > 0) { // pull the next item indent = (shuffler.PullNumber() % 86) + 1; } // now we need to copy the entire sourceImage onto the target, using this indent // iterate the y pixels for (int x = 0; x < rowWidth; x++) { for (int y = 0; y < rowHeight; y++) { // get this pixel PixelInformation pixel = sliceDatabase.GetPixel(x, y); // If the pixel object exists if (NullHelper.Exists(pixel)) { // get the new x offSetX = indent + startX + x; offSetY = (section * rowHeight) + y + startY + incrementedValue; if (offSetY < (targetDatabase.Height - 1)) { // Set the pixel color targetDatabase.SetPixelColor(offSetX, offSetY, pixel.Color, false, 0); } } } } } // Set the image TargetImageViewer.BackgroundImage = targetDatabase.DirectBitmap.Bitmap; // UPdate this UI Refresh(); } else { // not valid isValid = false; } } else { // not valid isValid = false; } // Show the user a message if (!isValid) { // show a message to the user MessageBox.Show("Not valid", "Invalid"); } }
/// <summary> /// event is fired when the 'CreateSubImagesButton' is clicked. /// </summary> private void CreateSubImagesButton_Click(object sender, EventArgs e) { try { // locals string imagePath = this.SourceImageControl.Text; int imageNumber = 0; int top = 0; int left = 0; string fileName = ""; Point topLeft; Rectangle size = new Rectangle(0, 0, this.WidthControl.IntValue, this.HeightControl.IntValue); PixelDatabase pixelDatabase = PixelDatabaseLoader.LoadPixelDatabase(imagePath, Refresh); int rows = RowsControl.IntValue; int columns = ColumnsControl.IntValue; Graph.Maximum = rows * columns; int height = HeightControl.IntValue; int width = WidthControl.IntValue; // Get the extension FileInfo fileInfo = new FileInfo(imagePath); // iterate the rows for (int row = 0; row < 6; row++) { // iterate the columns for (int column = 0; column < 6; column++) { // Increment the value for imageNumber imageNumber++; left = column * width; top = row * width; topLeft = new Point(left, top); size = new Rectangle(left, top, width, height); // create the subImage Image image = pixelDatabase.CreateSubImage(topLeft, size); // get the new file name without the extension string imageName = this.ImageNameControl.Text.Replace(fileInfo.Extension, ""); // set the fileName fileName = Path.Combine(this.OutputFolderControl.Text, imageName + imageNumber + fileInfo.Extension); // Save the file image.Save(fileName); Graph.Value = imageNumber; Graph.Refresh(); Application.DoEvents(); } } // Show the user a message MessageBox.Show("The sub images have been created.", "Success"); } catch (Exception error) { // show the user a message MessageBox.Show("An error occurred processing your image", "Oops. Something went wrong."); // for debugging only DebugHelper.WriteDebugError("CreateSubImagesButton_Click", this.Name, error); } }