private void buttonBrowseHeightmap_Click(object sender, EventArgs e) { OpenFileDialog openFileDialog = new OpenFileDialog( ); openFileDialog.Filter = "Tiled bitmap (.tbmp) |*.tbmp"; openFileDialog.Title = "Open Heightmap"; if (openFileDialog.ShowDialog( ) == DialogResult.OK) { TiledBitmap heightmap = TiledBitmap.Open(openFileDialog.FileName, true); if (heightmap.PixelFormat != TiledBitmapPixelFormat.Format16BitGrayScale) { MessageBox.Show("Heightmap format must be 16 bit grayscale."); } else { // Set path into heightmap text box textBoxHeightmap.Text = openFileDialog.FileName; SetupInitialParameters(heightmap.Width, heightmap.Height); } heightmap.Close( ); } }
private void ExportViaFreeImage(Metafile metafile, double width, double height) { Logger.Info("ExportViaFreeImage: Preset: {0}", Preset); Logger.Info("ExportViaFreeImage: Width: {0}; height: {1}", width, height); // Calculate the number of pixels needed for the requested // output size and resolution; size is given in points (1/72 in), // resolution is given in dpi. int px = (int)Math.Round(width / 72 * Preset.Dpi); int py = (int)Math.Round(height / 72 * Preset.Dpi); Logger.Info("ExportViaFreeImage: Pixels: x: {0}; y: {1}", px, py); Cancelling += Exporter_Cancelling; PercentCompleted = 10; _tiledBitmap = new TiledBitmap(px, py); FreeImageBitmap fib = _tiledBitmap.CreateFreeImageBitmap(metafile, EffectiveTransparency()); ConvertColor(fib); fib.SetResolution(Preset.Dpi, Preset.Dpi); fib.Comment = Versioning.SemanticVersion.Current.BrandName; PercentCompleted = 30; Logger.Info("ExportViaFreeImage: Saving {0} file", Preset.FileType); try { fib.Save( FileName, Preset.FileType.ToFreeImageFormat(), GetSaveFlags() ); } catch (Exception e) { Logger.Fatal("ExportViaFreeImage: FreeImageBitmap.Save() threw an exception!"); Logger.Fatal(e); throw; } finally { Cancelling -= Exporter_Cancelling; PercentCompleted = 50; } }
private bool ValidateMapParameters( ) { if (textBoxHeightmap.Text == "") { MessageBox.Show("Heightmap must be selected."); return(false); } if (textBoxOverlayImage.Text == "") { return(true); } using (TiledBitmap heightmap = TiledBitmap.Open(textBoxHeightmap.Text, true), overlaymap = TiledBitmap.Open(textBoxOverlayImage.Text, true)) { if (heightmap.PixelFormat != TiledBitmapPixelFormat.Format16BitGrayScale) { MessageBox.Show("Heightmap format is not 16 bit grayscale."); return(false); } if (overlaymap.PixelFormat != TiledBitmapPixelFormat.Format24BitRGB) { MessageBox.Show("Overlay image format is not 24 bit RGB."); return(false); } // check resolution if (overlaymap.Height % (heightmap.Height - 1) != 0 || overlaymap.Width % (heightmap.Width - 1) != 0) { MessageBox.Show("Heightmap/overlaymap dimension mismatch.\n\n Overlaymap dimensions must be:\n" + " overlaymap.Height = n * (heightmap.Height - 1)\n overlaymap.Width = n * (heightmap.Width - 1)\n" + " where n is an integer >= 1."); return(false); } } return(true); }
private void buttonBrowseOverlay_Click(object sender, EventArgs e) { OpenFileDialog openFileDialog = new OpenFileDialog( ); openFileDialog.Filter = "Tiled bitmap (.tbmp) |*.tbmp"; openFileDialog.Title = "Open Overlay Image"; if (openFileDialog.ShowDialog( ) == DialogResult.OK) { TiledBitmap overlaymap = TiledBitmap.Open(openFileDialog.FileName, true); if (overlaymap.PixelFormat != TiledBitmapPixelFormat.Format24BitRGB) { MessageBox.Show("Overlay image format must be 24 bit RGB."); } else { // Set path into overlay image text box textBoxOverlayImage.Text = openFileDialog.FileName; } overlaymap.Close( ); } }
public void SetUpAndRenderScene() { this.StopRender(); this.tracer.Scene = UnifiedScenesRepository.Scenes[this.TabText]; int tilesX = Convert.ToInt32(this.txtXParallel.Text); int tilesY = Convert.ToInt32(this.txtYParallel.Text); this.tiledBitmap = new TiledBitmap(tilesX, tilesY, (int)this.tracer.Scene.DefaultCamera.ResX, (int)this.tracer.Scene.DefaultCamera.ResY); if (this.tiledPictureViewControlView.TiledBitmap != null) { this.tiledPictureViewControlView.TiledBitmap.Dispose(); } this.tiledPictureViewControlView.TiledBitmap = tiledBitmap; int numOfWorkers = this.tiledBitmap.TilesX * this.tiledBitmap.TilesY; int renderPerTiles = Convert.ToInt32(this.toolStripTextBoxRenderByTiles.Text); ThreadPool.SetMinThreads(numOfWorkers / renderPerTiles, numOfWorkers / renderPerTiles); this.StartRender(); }