public byte[] HeatmapToByteArray(HeatmapArray ha) { // Scaled intensity: on interval (0,1) double[,] intensity = ha.GetScaledIntensity(); // Writing bytes (flattening 2d array) byte[] bytes = new byte[Len]; int pixNo; // pixel number for (int y = 0; y < Height; y++) { for (int x = 0; x < Width; x++) { pixNo = y * Width + x; // blue, green, red are 0; greyscale // bytes[4 * i] = 255; // R bytes[4 * pixNo + 1] = 255; // G // bytes[4 * i + 2] = 255; // B bytes[4 * pixNo + 3] = (byte)(254 * intensity[x, y]); // alpha (0=transparent, 255 =opaque) } } return(bytes); }
// Overlays heatmap onto source image public void Overlay(BitmapSource source, HeatmapArray heatmap) { // Bottom layer (background image) as byte array byte[] bottom = BmpToByteArray(source); // Top layer (heatmap) as byte array byte[] top = HeatmapToByteArray(heatmap); // Blending byte[] rawImage = Blend(bottom, top); // Storing result Result = BitmapSource.Create(Width, Height, 96d, 96d, Pf, null, rawImage, Stride); }
// Heatmap converted to bitmap public BitmapSource HeatmapToBitmap(HeatmapArray heatmap) { // Creating bitmap return(BitmapSource.Create(Width, Height, 96d, 96d, Pf, null, HeatmapToByteArray(heatmap), Stride)); }