/// <summary> /// Creates a bitmap from the HGT file, where each height corresponds to a color set by the setter. /// </summary> /// <param name="setter">Maps the (lowest, highest) interval with short.MinValue for missing height value into RGB colorspace.</param> /// <returns>Bitmap created using the setter.</returns> public System.Drawing.Bitmap ToBitmap(ColorSetter setter) { int size = (int)Math.Sqrt(data.Length); var bmp = new System.Drawing.Bitmap(size, size); using (var k = new LockBitmap.LockBitmap(bmp)) { for (int i = 0; i < data.Length; i++) { k.SetPixel(i % size, i / size, setter(Lowest, Highest, data[i])); } } return(bmp); }
public static void bitmapToGrayscale(Bitmap bm) { double coefR = 0.21, coefG = 0.71, coefB = 0.07; using (var lb = new LockBitmap.LockBitmap(bm)) { for (var y = 0; y < lb.Height; y++) { for (var x = 0; x < lb.Width; x++) { var color = lb.GetPixel(x, y); var intensity = (int)(coefR * color.R + coefG * color.G + coefB * color.B); var newColor = Color.FromArgb(intensity, intensity, intensity); lb.SetPixel(x, y, newColor); } } } }