Esempio n. 1
0
        private void loadHeightMap_Click(object sender, EventArgs e)
        {
            OpenFileDialog openFileDialog1 = new OpenFileDialog();

            openFileDialog1.Filter           = "All Graphics Types|*.bmp;*.png;*.jpg";
            openFileDialog1.FilterIndex      = 0;
            openFileDialog1.RestoreDirectory = true;

            if (openFileDialog1.ShowDialog() == DialogResult.OK)
            {
                Bitmap i = (Bitmap)Bitmap.FromFile(openFileDialog1.FileName);

                this.HeightMapBitmap        = new LockBitmap(i);
                this.HeightMapBitmapPreview = new LockBitmap(new Bitmap(i));
                {
                    HeightMapBitmapPreview.LockBits();

                    if ((HeightMapBitmapPreview.Width * HeightMapBitmapPreview.Height) > 4096 * 2048)
                    {
                        MessageBox.Show(this, "Error: Height map too large. Max size 4096x2048");
                        HeightMapBitmapPreview.UnlockBits();
                        return;
                    }
                    for (int x = 0; x < HeightMapBitmapPreview.Width; x++)
                    {
                        for (int y = 0; y < HeightMapBitmapPreview.Height; y++)
                        {
                            byte h = HeightMapBitmapPreview.GetHeight(x, y);
                            if (h < seaLevel.Value)
                            {
                                HeightMapBitmapPreview.SetPixel(x, y, Color.FromArgb(255, 69, 91, 186));
                            }
                        }
                    }
                    HeightMapBitmapPreview.UnlockBits();
                    preview.Image = HeightMapBitmapPreview.Source;
                    preview.Invalidate();
                    //using (Graphics gg = Graphics.FromImage(landDrawBitmap.Source))
                    {
                        //  gg.Clear(Color.Transparent);
                        //    gg.SmoothingMode = SmoothingMode.Default;
                        //      gg.DrawImage(i, new Rectangle(0, 0, preview.Width, preview.Height));
                    }
                }
            }
        }
Esempio n. 2
0
 private void seaLevel_ValueChanged(object sender, EventArgs e)
 {
     this.HeightMapBitmapPreview = new LockBitmap(new Bitmap(HeightMapBitmap.Source));
     {
         HeightMapBitmapPreview.LockBits();
         for (int x = 0; x < HeightMapBitmapPreview.Width; x++)
         {
             for (int y = 0; y < HeightMapBitmapPreview.Height; y++)
             {
                 byte h = HeightMapBitmapPreview.GetHeight(x, y);
                 if (h < seaLevel.Value)
                 {
                     HeightMapBitmapPreview.SetPixel(x, y, Color.FromArgb(255, 69, 91, 186));
                 }
             }
         }
         HeightMapBitmapPreview.UnlockBits();
         preview.Image = HeightMapBitmapPreview.Source;
         preview.Invalidate();
     }
 }