public void loadElevationMap(string path) { Bitmap elevationBitmap = (Bitmap)Bitmap.FromFile(path); // For speed improvement, the bitmap must be locked and accessed unsafely. // v lock entire bitmap v readonly v use pixel format of bitmap var bmpdata = elevationBitmap.LockBits(new Rectangle(0, 0, elevationBitmap.Width, elevationBitmap.Height), System.Drawing.Imaging.ImageLockMode.ReadOnly, elevationBitmap.PixelFormat); int stride = bmpdata.Stride; int colorsize = System.Drawing.Bitmap.GetPixelFormatSize(bmpdata.PixelFormat) / 8; // Divide by 8 because 1 byte is 8 bits and FormatSize returns bits. elevationMap = new int[elevationBitmap.Width, elevationBitmap.Height]; for (int y = 0; y < elevationBitmap.Height; y++) { for (int x = 0; x < elevationBitmap.Width; x++) { Color point = fetchColor(x, y, stride, colorsize, bmpdata); int height; if (point.R == 0) { height = point.B; } else { height = point.B + 25; } elevationMap[x, y] = height; } } // Once we are done, immediately unlock the bitmap elevationBitmap.UnlockBits(bmpdata); smoothedElevationMap = Blur.gaussianBlur(elevationMap, 8); Console.WriteLine("Loaded elevation map sized {0}x{1}", elevationMap.GetUpperBound(0), elevationMap.GetUpperBound(1)); }
public void loadElevationMap(string path) { Bitmap elevationBitmap = (Bitmap)Bitmap.FromFile(path); elevationMap = new int[elevationBitmap.Width, elevationBitmap.Height]; for (int y = 0; y < elevationBitmap.Height; y++) { for (int x = 0; x < elevationBitmap.Width; x++) { Color point = elevationBitmap.GetPixel(x, y); int height; if (point.R == 0) { height = point.B; } else { height = point.B + 25; } elevationMap[x, y] = height; } } smoothedElevationMap = Blur.gaussianBlur(elevationMap, 8); Console.WriteLine("Loaded elevation map sized {0}x{1}", elevationMap.GetUpperBound(0), elevationMap.GetUpperBound(1)); }