public static Bitmap ToImage(int[,] energy) { //throw new NotImplementedException(); //int[] bytes = new int[Width * Height * 3]; //for (int i = 0; i < Height; i++) //{ // for (int j = 0; j < Width; j++) // { // bytes[3 * j + i * Width] = Pixels[j, i, 0]; // bytes[3 * j + i * Width + 1] = Pixels[j, i, 1]; // bytes[3 * j + i * Width + 2] = Pixels[j, i, 2]; // } //} //var img = Image.FromStream(new MemoryStream()); //return null; var bmp = new Bitmap(Width, Height); var bmpData = new LockBitmap(bmp); bmpData.LockBits(); for (var i = 0; i < Width; i++) { for (var j = 0; j < Height; j++) { bmpData.SetPixel(i, j, Color.FromArgb(energy[i, j], energy[i, j], energy[i, j])); } } bmpData.UnlockBits(); return(bmp); }
protected override double Calculation(LockBitmap originalBmp, LockBitmap steganoBmp) { Color orig; Color steg; var originalDiffernce = 0.0; var totalDifference = 0.0; for (var y = 0; y < originalBmp.Height; y++) { for (var x = 0; x < originalBmp.Width; x++) { orig = originalBmp.GetPixel(x, y); steg = steganoBmp.GetPixel(x, y); originalDiffernce += Math.Pow(Math.Abs(orig.R) + Math.Abs(orig.G) + Math.Abs(orig.B), 2); totalDifference += Math.Pow(Math.Abs(orig.R - steg.R) + Math.Abs(orig.G - steg.G) + Math.Abs(orig.B - steg.B), 2); } } return(originalDiffernce / totalDifference); }
public static IEnumerable <Point> Contains(Bitmap MappedOne, Bitmap MappedTwo, double Percentage) { LockBitmap lockedOne = new LockBitmap(MappedOne); LockBitmap lockedTwo = new LockBitmap(MappedTwo); lockedOne.LockBits(); lockedTwo.LockBits(); try { for (int x = 0; x < (MappedOne.Width - MappedTwo.Width + 1); x++) { for (int y = 0; y < (MappedOne.Height - MappedTwo.Height + 1); y++) { //If they meet the specified percentage (or more of course) it works //if (Compare.ComparePercentage(MappedOne.Clone(new Rectangle(x, y, MappedTwo.Width, MappedTwo.Height), MappedOne.PixelFormat), MappedTwo, Percentage, true) >= Percentage) { if (Compare.ExactMatch(lockedOne, x, y, MappedTwo.Width, MappedTwo.Height, lockedTwo)) { yield return(new Point(x, y)); y += MappedTwo.Height; //Move so we don't get a bunch of matches here } } } } finally { lockedOne.UnlockBits(); lockedTwo.UnlockBits(); } }
public static Bitmap DetectEdges(Bitmap source, int threshold) { // needs an unchanged copy of itself for reference var input = new LockBitmap(source); var output = new Bitmap(source.Width, source.Height); var bmpOutput = new LockBitmap(output); input.LockBits(); bmpOutput.LockBits(); Parallel.For(1, input.Height - 1, y => { Parallel.For(1, input.Width - 1, x => { // taking input from the unchanged copy var nextY = input.GetPixel(x, y + 1); var prevY = input.GetPixel(x, y - 1); var nextX = input.GetPixel(x + 1, y); var prevX = input.GetPixel(x - 1, y); int xRed = nextX.R - prevX.R; int yRed = nextY.R - prevY.R; double result = Min(0.5 * Sqrt(xRed * xRed + yRed * yRed), 255); if (threshold > result) // output in another object bmpOutput.SetPixel(x, y, Color.White); else bmpOutput.SetPixel(x, y, Color.Black); }); }); bmpOutput.UnlockBits(); input.UnlockBits(); return output; }
protected override double Calculation(LockBitmap originalBmp, LockBitmap steganoBmp) { Color orig; Color steg; var size = originalBmp.Height * originalBmp.Width; var totalDifference = 0.0; var maxDifference = 0.0; double currentDifference; for (var y = 0; y < originalBmp.Height; y++) { for (var x = 0; x < originalBmp.Width; x++) { orig = originalBmp.GetPixel(x, y); steg = steganoBmp.GetPixel(x, y); currentDifference = Math.Pow(Math.Abs(orig.R) + Math.Abs(orig.G) + Math.Abs(orig.B), 2); if (currentDifference >= maxDifference) { maxDifference = currentDifference; } totalDifference += Math.Pow(Math.Abs(orig.R - steg.R) + Math.Abs(orig.G - steg.G) + Math.Abs(orig.B - steg.B), 2); } } return(size * maxDifference / totalDifference); }
protected LockBitmap LockBitmap(string src) { var lockBitmap = new LockBitmap(new Bitmap(src)); lockBitmap.LockBits(); return(lockBitmap); }
private void loadAmplitudeButton_Click(object sender, EventArgs e) { if (loadAmplitudeDialog.ShowDialog() == DialogResult.OK) { inputAmplitudeImage.Load(loadAmplitudeDialog.FileName); var amplitudeImage = new Bitmap(inputAmplitudeImage.Image); var lockedBmp = new LockBitmap(amplitudeImage); lockedBmp.LockBits(); _n = lockedBmp.Height; _inputData = new cuDoubleComplex[_n * _n]; _spwPhaseShift = new double[_n * _n]; double k = 2 * Math.PI / _lambda; double temp = _lambda * _lambda / _h / _h / _n / _n; Parallel.For(0, _n, i => { for (int j = 0; j < _n; j++) { var pixelValue = lockedBmp.GetPixel(i, j); _inputData[i * _n + j].real = Math.Sqrt(pixelValue.G); _inputData[i * _n + j].imag = 0f; _spwPhaseShift[i * _n + j] = k * _z * Math.Sqrt( 1 - temp * ((_n / 2 - i) * (_n / 2 - i) + (_n / 2 - j) * (_n / 2 - j))); } }); lockedBmp.UnlockBits(); } }
public void UpdateFromProvinces() { Width *= 4; Height *= 4; TerrainMap.LockBits(); Refine(); File.Delete(Globals.MapOutputTotalDir + "map\\terrain.bmp"); GrayBMP_File.CreateGrayBitmapFile(TerrainMap.Source, Globals.MapOutputTotalDir + "map\\terrain.bmp"); TerrainMap.Source.Dispose(); TerrainMap = null; GrayBMP_File.CreateGrayBitmapFile(Trees.Source, Globals.MapOutputTotalDir + "map\\trees.bmp", true); LockBitmap rivers = new LockBitmap(Width, Height); rivers.LockBits(); for (int x = 0; x < Width; x++) { for (int y = 0; y < Height; y++) { rivers.SetPixel(x, y, Color.FromArgb(255, 255, 0, 128)); } } rivers.UnlockBits(); GrayBMP_File.CreateGrayBitmapFile(rivers.Source, Globals.MapOutputTotalDir + "map\\rivers.bmp", false, true); }
//Rendering the image call elevate private void renderResult(RenderData input) { if (input == null) { return; } LockBitmap resultLB = new LockBitmap(new Bitmap((int)(input.Width), (int)(input.Height * 0.5) + heightExcess), false); if (cores == 1) { elevate(input, resultLB, 0, 1); } else { Task[] thread = new Task[(int)cores]; for (int i = 0; i < cores; i++) { int thmp = (int)(i + 1); thread[i] = new Task(() => elevate(input, resultLB, thmp / cores - 1 / cores, thmp / cores)); } for (int i = 0; i < cores; i++) { thread[i].Start(); } for (int i = 0; i < cores; i++) { thread[i].Wait(); } } Result = resultLB.returnBitmap(); }
private void bNew_Click(object sender, EventArgs e) { //inputLB = new LockBitmap(new Bitmap("../input/test_256x256.png"), false); inputLB = new LockBitmap(new Bitmap(128, 128), false); render(true); timer1.Enabled = true; }
public Bitmap ConvertCanvasToBitmap(Canvas canvas) { if (canvas == null) throw new NullReferenceException("'canvas' can't be null"); int width = canvas.Width; int height = canvas.Height; Bitmap image = new Bitmap(width, height); LockBitmap lockBitmap = new LockBitmap(image); lockBitmap.LockBits(); Parallel.ForEach(Partitioner.Create(0, height), rangeHeight => { for(int y = rangeHeight.Item1; y < rangeHeight.Item2; y++) for (int x = 0; x < width; x++) lockBitmap.SetPixel(x, y, canvas.GetColor(x, y)); }); lockBitmap.UnlockBits(); #region Obsolete /* for (int y = 0; y < height; y++) { for (int x = 0; x < width; x++) image.SetPixel(x, y, canvas.GetColor(x, y)); } */ #endregion return image; }
public void SetBitmap(Bitmap bmp, bool visible) { pictureBox.Image = bmp; int x = Width = bmp.Width; int y = Height = bmp.Height; Visible = false; bmpLock = new LockBitmap(bmp); bmpLock.LockBits(); // Resize "auto" de la fenêtre while ((pictureBox.Width < bmp.Width || pictureBox.Height < bmp.Height) && x - 1 > Width && y - 1 > Height) { if (pictureBox.Width < bmp.Width) { Width = ++x; } if (pictureBox.Height < bmp.Height) { Height = ++y; } if (x > 20000 || y > 20000) { break; } } bmpLock.UnlockBits(); Visible = visible; }
private void btnFind_Click(object sender, EventArgs e) { Save(); Point point = GetPointForTextBox(txtStartPos); Color color = GetColorForTextBox(txtRgb); int width, height, diff = 0; int.TryParse(txtHeight.Text, out height); int.TryParse(txtWidth.Text, out width); int.TryParse(txtDiff.Text, out diff); if (point.IsZero() || color == Color.Empty || width == 0 || height == 0) { return; } LockBitmap lockB = ImgUtils.GetLockBitmap(point.X, point.Y, width, height); lockB.LockBits(); var points = FindPoints(point, lockB, color, diff); txtOutput.Clear(); if (points.Count == 0) { txtOutput.AppendText("No Result!"); } else { for (int i = 0; i < points.Count; i++) { var tuple = points[i]; txtOutput.AppendText($"{tuple.Item1.X}, {tuple.Item1.Y} | diff: {tuple.Item2}{Environment.NewLine}"); } } lockB.UnlockBits(); }
/// <summary> /// カラー→モノクロ変換 /// </summary> /// <param name="src"></param> /// <param name="dst"></param> private unsafe static void cvt_COLOR_BGR2GRAY(Bitmap src, Bitmap dst) { using (var lbSrc = new LockBitmap(src)) using (var lbDst = new LockBitmap(dst)) { var pSrc = (byte *)lbSrc.Scan0; var pDst = (byte *)lbDst.Scan0; var width = lbSrc.Width; var height = lbSrc.Height; var channel = lbSrc.Channel; Parallel.For(0, height, y => { // 行の先頭ポインタ byte *pLineSrc = pSrc + y * lbSrc.Stride; byte *pLineDst = pDst + y * lbDst.Stride; for (int x = 0; x < width; x++) { // 輝度値(モノクロ)の設定 // gray = ((0.299 * R + 0.587 * G + 0.114 * B) * 256) / 256 pLineDst[0] = (byte)((77 * pLineSrc[2] + 150 * pLineSrc[1] + 29 * pLineSrc[0]) >> 8); // 次の画素へ pLineSrc += channel; pLineDst++; } } ); } }
//Prepare the heightMap call rotate and shadow private LockBitmap prepareMap(LockBitmap inputLB) { LockBitmap resultLB = new LockBitmap((int)(inputLB.Width * 1.5), (int)(inputLB.Height * 1.5)); if (cores == 1) { rotate(inputLB, resultLB, 0, 1); } else { Task[] thread = new Task[(int)cores]; for (int i = 0; i < cores; i++) { int thmp = (int)(i + 1); thread[i] = new Task(() => rotate(inputLB, resultLB, thmp / cores - 1 / cores, thmp / cores)); } for (int i = 0; i < cores; i++) { thread[i].Start(); } for (int i = 0; i < cores; i++) { thread[i].Wait(); } } shadows(resultLB, ShadowQuality); return(resultLB); }
private void button2_Click(object sender, EventArgs e) { //Paimamas pradinis bitmap Bitmap bmp = (Bitmap)Image.FromFile("..\\..\\Pradinis.jpg"); LockBitmap lockBitmap = new LockBitmap(bmp); //Baitai perkopijuojami į LockBitmap klasę lockBitmap.LockBits(); //Baitai užrakinami Stopwatch sw = new Stopwatch(); sw.Start(); for (int i = 0; i < lockBitmap.GetBytesCount(); i = i + 3) { //Pagal 3 pikelio komponentes naudojantis skaistumo formule paskaičiuojama komponentė byte gray = (byte)(lockBitmap.Bytes[i] * 0.2126 + lockBitmap.Bytes[i + 1] * 0.7152 + lockBitmap.Bytes[i + 2] * 0.0722); //Komponentė priskiriama 3 pikelio baitams lockBitmap.Bytes[i] = lockBitmap.Bytes[i + 1] = lockBitmap.Bytes[i + 2] = gray; } sw.Stop(); lockBitmap.UnlockBits(); //Baitai atrakinami richTextBox1.AppendText("Užtrukęs laikas nelygiagrečiai: " + sw.ElapsedMilliseconds + "\n"); pictureBox2.Image = bmp; //Atvaizduojami rezultatai bmp.Save("..\\..\\GalinisNelyg.jpg"); }
/// <summary> /// チャンネル入れ替え /// </summary> /// <param name="src"></param> /// <param name="dst"></param> private unsafe static void cvt_COLOR_BGR2RGB(Bitmap src, Bitmap dst) { using (var lbSrc = new LockBitmap(src)) using (var lbDst = new LockBitmap(dst)) { var pSrc = (byte *)lbSrc.Scan0; var pDst = (byte *)lbDst.Scan0; var width = lbSrc.Width; var height = lbSrc.Height; var channel = lbSrc.Channel; Parallel.For(0, height, y => { // 行の先頭ポインタ byte *pLineSrc = pSrc + y * lbSrc.Stride; byte *pLineDst = pDst + y * lbDst.Stride; for (int x = 0; x < width; x++) { // チャンネル入れ替え pLineDst[0] = pLineSrc[2]; pLineDst[1] = pLineSrc[1]; pLineDst[2] = pLineSrc[0]; // 次の画素へ pLineSrc += channel; pLineDst += channel; } } ); } }
public static void Pixellate(this LockBitmap bmp, Rectangle rectangle, int pixelSize) { // look at every pixel in the rectangle while making sure we're within the image bounds for (int xx = rectangle.X; xx < rectangle.X + rectangle.Width && xx < bmp.Width; xx += pixelSize) { for (int yy = rectangle.Y; yy < rectangle.Y + rectangle.Height && yy < bmp.Height; yy += pixelSize) { int offsetX = pixelSize / 2; int offsetY = pixelSize / 2; // make sure that the offset is within the boundry of the image while (xx + offsetX >= bmp.Width) { offsetX--; } while (yy + offsetY >= bmp.Height) { offsetY--; } // get the pixel color in the center of the soon to be pixelated area Color pixel = bmp.GetPixel(xx + offsetX, yy + offsetY); // for each pixel in the pixelate size, set it to the center color for (int x = xx; x < xx + pixelSize && x < bmp.Width; x++) { for (int y = yy; y < yy + pixelSize && y < bmp.Height; y++) { bmp.SetPixel(x, y, pixel); } } } } }
/// <summary> /// 像素方式访问 /// </summary> private void TestBlendImageCode2() { var bmp = new Bitmap(AppDomain.CurrentDomain.BaseDirectory + "2016-01-12-15h.png"); Benchmark.Start(); LockBitmap lockBitmap = new LockBitmap(bmp); lockBitmap.LockBits(); Color compareClr = Color.FromArgb(255, 255, 255, 255); for (int y = 0; y < lockBitmap.Height; y++) { for (int x = 0; x < lockBitmap.Width; x++) { if (lockBitmap.GetPixel(x, y) == compareClr) { lockBitmap.SetPixel(x, y, Color.Red); } } } lockBitmap.UnlockBits(); Benchmark.End(); double seconds = Benchmark.GetSeconds(); bmp.Dispose(); }
public static void ChangeColor(string path) { Bitmap bmp = (Bitmap)Image.FromFile(path); //Benchmark.Start(); LockBitmap lockBitmap = new LockBitmap(bmp); lockBitmap.LockBits(); Color compareClr = Color.FromArgb(255, 255, 255, 255); for (int y = 0; y < lockBitmap.Height; y++) { for (int x = 0; x < lockBitmap.Width; x++) { if (lockBitmap.GetPixel(x, y) == compareClr) { lockBitmap.SetPixel(x, y, Color.Red); } } } lockBitmap.UnlockBits(); //Benchmark.End(); //double seconds = Benchmark.GetSeconds(); bmp.Save(path); }
//add shadows private void shadows(LockBitmap resultLB, int resulution) { if (resulution == 0) { return; } byte[] resultRGB = resultLB.getData(); int width = resultLB.Width, height = resultLB.Height; for (int iy = 0; iy < (int)(height); iy++) //y 0 to 1 { for (int ix = 0; ix < width; ix += resulution) //x 0 to 1 { //get position int offset = (ix + iy * width) * 4; int i = 0; float shadowHeight = (resultRGB[offset + 1]); while (resultRGB[offset + 2] < shadowHeight) { if (i > 0) { resultRGB[offset + 2] = (byte)(shadowHeight * 1f); } if (resultRGB[offset + 1] > shadowHeight + 1) { break; } i++; shadowHeight -= 1f; offset += 4; } } } }
public override IActionProperty CheckCondition(ref LockBitmap lockBitmap) { ActionProperty actionModel = new ActionProperty(); byte[] pixels = lockBitmap.Pixels; var castSettings = ((PixelClickerPrototype.Settings)Settings); int width = lockBitmap.Width; var points = new List <DbscanPoint>(); for (var n = pixels.Length - 1; n >= 0; n--) { var nMultiplied = n * 4; if (nMultiplied >= pixels.Length) { continue; } if (!(pixels[nMultiplied + 2] >= 250 && pixels[nMultiplied + 1] <= 5 && pixels[nMultiplied] <= 20)) { continue; } var x = GetXFromByte(n, width); var y = GetYFromByte(n, x, width); points.Add(new DbscanPoint(x, y)); } if (points.Count == 0) { return(actionModel); } var heightAdjusted = Settings.SearchMethod != SearchMethod.AnyWhere ? 1.75 : 1; HighestLowest target = CalculateTarget(points, heightAdjusted); if (target == null) { return(actionModel); } int healthBarHeight = GetHealthBarHeight(target, castSettings.MaximumHealthBarHeight); int offset = (castSettings.MaximumHealthBarHeight - healthBarHeight) * 4; actionModel.RelativeToScreenPoint = new Point(Settings.SearchPosition.X + target.HighestPoint.X, Settings.SearchPosition.Y + target.HighestPoint.Y); actionModel.AimPoint = new Point(target.HighestPoint.X + (castSettings.XOffset - offset), target.HighestPoint.Y + (castSettings.YOffset - offset)); actionModel.Settings = castSettings; actionModel.DoAction = true; actionModel.Time = DateTime.Now; actionModel.PointsInfo = target; return(actionModel); }
//Rendering the image call elevate private void renderResult(LockBitmap inputMap) { if (inputMap == null) { return; } LockBitmap inputLB = inputMap; LockBitmap resultLB = new LockBitmap(new Bitmap((int)(inputMap.Width), (int)(inputMap.Height * 0.5) + heightExcess), false); byte[] inputRGB = inputLB.getData(); byte[] resultRGB = resultLB.getData(); if (cores == 1) { elevate(inputLB, resultLB, 0, 1); } else { Task[] thread = new Task[(int)cores]; for (int i = 0; i < cores; i++) { int thmp = (int)(i + 1); thread[i] = new Task(() => elevate(inputLB, resultLB, thmp / cores - 1 / cores, thmp / cores)); } for (int i = 0; i < cores; i++) { thread[i].Start(); } for (int i = 0; i < cores; i++) { thread[i].Wait(); } } result = resultLB.returnBitmap(); }
/// <summary> /// Lutに基づいた二値化処理 /// </summary> /// <param name="src">入力画像</param> /// <param name="dst">出力画像</param> /// <param name="lut">Lut</param> public unsafe static void Threshold(this Bitmap src, Bitmap dst, byte[] lut) { using (var lbSrc = new LockBitmap(src)) using (var lbDst = new LockBitmap(dst)) { var pSrc = (byte *)lbSrc.Scan0; var pDst = (byte *)lbDst.Scan0; var width = lbSrc.Width; var height = lbSrc.Height; var channel = lbSrc.Channel; Parallel.For(0, height, y => { // 行の先頭ポインタ byte *pLineSrc = pSrc + y * lbSrc.Stride; byte *pLineDst = pDst + y * lbDst.Stride; for (int x = 0; x < width; x++) { for (int ch = 0; ch < channel; ch++) { // LUTを介した二値化処理 pLineDst[ch] = lut[pLineSrc[ch]]; } // 次の画素へ pLineSrc += channel; pLineDst += channel; } } ); } }
//rotate byte pixel array private void rotate(LockBitmap inputLB, LockBitmap resultLB, float start, float end) { byte[] inputRGB = inputLB.getData(); byte[] resultRGB = resultLB.getData(); int inputW = inputLB.Width, inputH = inputLB.Height, resultW = resultLB.Width, resultH = resultLB.Height; double sinma = Math.Sin(-angle * 3.14159265 / 180); double cosma = Math.Cos(-angle * 3.14159265 / 180); for (int x = (int)(resultW * start); x < (int)(resultW * end); x++) { for (int y = 0; y < resultH; y++) { int hwidth = (int)(inputW / 2); int hheight = (int)(inputH / 2); int xt = (int)(x - hwidth * 1.5); int yt = (int)(y - hheight * 1.5); int xs = (int)((cosma * (xt) - sinma * (yt)) + hwidth); int ys = (int)((sinma * (xt) + cosma * (yt)) + hheight); int offsetDst = (x + y * resultW) * 4; int offsetSrc = (xs + ys * inputW) * 4; if (xs >= 0 && xs < inputW && ys >= 0 && ys < inputH) { resultRGB[offsetDst + 0] = inputRGB[offsetSrc + 0]; //texture resultRGB[offsetDst + 1] = inputRGB[offsetSrc + 1]; //height } } } }
private void PreProcess(object sender, DoWorkEventArgs e) { var lockBitmapModel = new LockBitmap(SnipImage((Bitmap)e.Argument)); lockBitmapModel.LockBits(); var actionModel = CheckCondition(ref lockBitmapModel); if (ActiveWindow.Name.ToLower().Contains(Settings.WindowName.ToLower())) { Action.DoAction(actionModel); } lockBitmapModel.UnlockBits(); Bitmap drawBitmap = null; if (Settings.Draw) { drawBitmap = new Bitmap(lockBitmapModel.Source); Draw(ref drawBitmap); } _fps += 1; if (_fpsStopWatch.ElapsedMilliseconds >= 1000) { Settings.LastFps = _fps; _fps = 0; _fpsStopWatch.Restart(); } lockBitmapModel.Dispose(); drawBitmap?.Dispose(); }
private void CreateHeightMap(LockBitmap provinceMap) { Map.LockBits(); provinceMap.LockBits(); // NewMap.LockBits(); for (int x = 0; x < Width; x++) { for (int y = 0; y < Height; y++) { float height = Map.GetHeight(x, y) / 255.0f; if (height < 76 / 255.0f) { height = 76 / 255.0f; } if (height >= 96 && ProvinceBitmapManager.instance.colorProvinceMap[provinceMap.GetPixel(x, y)].isSea) { height = 94; } Map.SetPixel(x, y, Color.FromArgb(255, (int)(255 * height), (int)(255 * height), (int)(255 * height))); } } provinceMap.UnlockBits(); ConvertTo24bpp(provinceMap.Source).Save(Globals.MapOutputTotalDir + "map\\provinces.bmp", System.Drawing.Imaging.ImageFormat.Bmp); provinceMap = null; ProvinceBitmapManager.instance.colorProvinceMap.Clear(); ProvinceBitmapManager.instance.colorMap.Clear(); Map.UnlockBits(); }
private void UnusedGenerate_Depth(Bitmap bm) { this.DepthMetaData.Vectors = new List <Vector3>(); LockBitmap lockBitmap = new LockBitmap(bm); lockBitmap.LockBits(); byte[] pixelData = lockBitmap.Pixels; DepthMetaData = new DepthMetaData(); DepthMetaData.FrameData = new ushort[pixelData.GetLength(0)]; //depthArr = new uint[bm.Width, bm.Height]; for (int iy = 0; iy < bm.Height; iy++) { int step24 = bm.Width * 3 * iy; for (int ix = 0; ix < bm.Width; ix++) { int pixel24 = step24 + 3 * ix; ushort depth = BitConverter.ToUInt16(pixelData, pixel24); int depthIndex = (iy * DepthMetaData.XDepthMaxRealSense) + ix; if (depth != 0) { Vector3 v = ConvertDepthTomm(ix, iy, depth); this.DepthMetaData.Vectors.Add(v); DepthMetaData.FrameData[depthIndex] = Convert.ToUInt16(v.Z); } } } lockBitmap.UnlockBits(); //--------------- }
public ImageCpc(ConvertDelegate fctConvert) { InitializeComponent(); int tx = pictureBox.Width; int ty = pictureBox.Height; bmp = new Bitmap(tx, ty); pictureBox.Image = bmp; bmpLock = new LockBitmap(bmp); bitmapCpc = new BitmapCpc(640, 400, 1); // ### for (int i = 0; i < 16; i++) { // Générer les contrôles de "couleurs" colors[i] = new Label(); colors[i].BorderStyle = BorderStyle.FixedSingle; colors[i].Location = new Point(4 + i * 48, 568); colors[i].Size = new Size(40, 32); colors[i].Tag = i; colors[i].Click += ClickColor; Controls.Add(colors[i]); // Générer les contrôles de "bloquage couleur" lockColors[i] = new CheckBox(); lockColors[i].Location = new Point(16 + i * 48, 600); lockColors[i].Size = new Size(20, 20); lockColors[i].Tag = i; lockColors[i].Click += ClickLock; Controls.Add(lockColors[i]); lockColors[i].Update(); } Reset(); ChangeZoom(1); Convert = fctConvert; }
public void MajProjet(Projet prj, bool newCpc) { int tx = pictureBox.Width = prj.Cx * 8; int ty = pictureBox.Height = prj.Cy * 16; if (newCpc) { bitmapCpc = new BitmapCpc(tx, ty, prj.Mode); } bmp = new Bitmap(tx, ty); pictureBox.Image = bmp; bmpLock = new LockBitmap(bmp); vScrollBar.Height = ty; vScrollBar.Left = tx + 3; hScrollBar.Width = tx; hScrollBar.Top = ty + 3; if (autoRecalc.Checked) { bpRecalc_Click(this, null); } else { Render(); } }
public Image ProcessImage(ImageFactory factory) { var bmp = factory.Bitmap; Bitmap newbmp = null; try { int height = bmp.Height; int width = bmp.Width; newbmp = new Bitmap(width, height); LockBitmap lbmp = new LockBitmap(bmp); LockBitmap newlbmp = new LockBitmap(newbmp); lbmp.LockBits(); newlbmp.LockBits(); Color pixel; int[] Gauss = { 1, 2, 1, 2, 4, 2, 1, 2, 1 }; for (int x = 1; x < width - 1; x++) { for (int y = 1; y < height - 1; y++) { int r = 0, g = 0, b = 0; int Index = 0; for (int col = -1; col <= 1; col++) { for (int row = -1; row <= 1; row++) { pixel = lbmp.GetPixel(x + row, y + col); r += pixel.R * Gauss[Index]; g += pixel.G * Gauss[Index]; b += pixel.B * Gauss[Index]; Index++; } } r /= 16; g /= 16; b /= 16; r = r > 255 ? 255 : r; r = r < 0 ? 0 : r; g = g > 255 ? 255 : g; g = g < 0 ? 0 : g; b = b > 255 ? 255 : b; b = b < 0 ? 0 : b; newlbmp.SetPixel(x - 1, y - 1, Color.FromArgb(r, g, b)); } } lbmp.UnlockBits(); newlbmp.UnlockBits(); } catch (Exception ex) { newbmp?.Dispose(); throw new ImageProcessingException("Error processing image with " + GetType().Name, ex); } return(newbmp); }
public Bitmap GenerateMiniMap() { LockBitmap lockBitmap = new LockBitmap(World.Width, World.Height); byte[] data = lockBitmap.getData(); renderMinimap(lockBitmap.getData()); return(lockBitmap.returnBitmap()); }
public static Bitmap LinearFilter(this Bitmap source, Func<Color, Color> map) { var bmp = new LockBitmap(source); bmp.LockBits(); Parallel.For(0, bmp.Height, y => { Parallel.For(0, bmp.Width, x => { var input = bmp.GetPixel(x, y); bmp.SetPixel(x, y, map(input)); }); }); bmp.UnlockBits(); return source; }
public Canvas ConvertBitmapToCanvas(Bitmap image) { if (image == null) throw new NullReferenceException("'image' can't be null"); int width = image.Width; int height = image.Height; Canvas canvas = new Canvas(new Resolution(width, height)); LockBitmap lockBitmap = new LockBitmap(image); lockBitmap.LockBits(); if (height * width > 6000) { Parallel.ForEach(Partitioner.Create(0, height), rangeHeight => { for (int y = rangeHeight.Item1; y < rangeHeight.Item2; y++) for (int x = 0; x < width; x++) canvas.SetColor(x, y, lockBitmap.GetPixel(x, y)); }); } else { for (int y = 0; y < height; y++) for (int x = 0; x < width; x++) canvas.SetColor(x, y, lockBitmap.GetPixel(x, y)); } /* Parallel.ForEach(Partitioner.Create(0, height), rangeHeight => { for (int y = rangeHeight.Item1; y < rangeHeight.Item2; y++) Parallel.ForEach(Partitioner.Create(0, width), rangeWidth => { for (int x = 0; x < width; x++) canvas.SetColor(x, y, lockBitmap.GetPixel(x, y)); } }); */ lockBitmap.UnlockBits(); #region Obsolete /* for (int y = 0; y < height; y++) for (int x = 0; x < width; x++) canvas.SetColor(x, y, image.GetPixel(x, y)); */ #endregion return canvas; }
/*public ImageTexeler(Bitmap img, int paletteMaxNum) { this.img = img; int tx = img.Width / 4; int ty = img.Height / 4; palettes = new Color[tx * ty][]; paletteCounts = new int[tx * ty]; paletteNumbers = new int[tx, ty]; paletteDiffs = new float[tx * ty, tx * ty]; int palNum = 0; for (int x = 0; x < tx; x++) for (int y = 0; y < ty; y++) { ImageIndexerFast iif = new ImageIndexerFast(img, x * 4, y * 4); palettes[palNum] = iif.palette; paletteNumbers[x, y] = palNum; paletteCounts[palNum] = 1; int similar = calcPaletteDiffs(palNum); /* if (similar != -1) { paletteCounts[palNum] = 0; paletteCounts[similar]++; paletteNumbers[x, y] = similar; } palNum++; } while (countUsedPalettes() > paletteMaxNum) { Console.Out.WriteLine(countUsedPalettes()); int besta = -1; int bestb = -1; float bestDif = float.MaxValue; //Find the two most similar palettes for (int i = 0; i < palettes.Length; i++) { if (paletteCounts[i] == 0) continue; for (int j = 0; j < palettes.Length; j++) { if (i == j) continue; if (paletteCounts[j] == 0) continue; if (paletteDiffs[i, j] < bestDif) { bestDif = paletteDiffs[i, j]; besta = j; bestb = i; } } } //Merge the Palettes!!! palettes[besta] = palMerge(palettes[besta], palettes[bestb]); calcPaletteDiffs(besta); paletteCounts[besta] += paletteCounts[bestb]; paletteCounts[bestb] = 0; for (int x = 0; x < tx; x++) for (int y = 0; y < ty; y++) if (paletteNumbers[x, y] == bestb) paletteNumbers[x, y] = besta; } //CREATE THE FINAL PAL int currNum = 0; finalPalette = new Color[paletteMaxNum * 4]; int[] newPalNums = new int[palettes.Length]; for (int i = 0; i < palettes.Length; i++) { if (paletteCounts[i] != 0) { transparentToTheEnd(palettes[i]);// newPalNums[i] = currNum; Array.Copy(palettes[i], 0, finalPalette, currNum * 4, 4); currNum++; } } ByteArrayOutputStream texDat = new ByteArrayOutputStream(); ByteArrayOutputStream f5Dat = new ByteArrayOutputStream(); for (int y = 0; y < ty; y++) for (int x = 0; x < tx; x++) { //Find out if texel has transparent. bool hasTransparent = false; for (int yy = 0; yy < 4; yy++) for (int xx = 0; xx < 4; xx++) { Color coll = img.GetPixel(x * 4 + xx, y * 4 + yy); if (coll.A < 128) hasTransparent = true; } //WRITE THE IMAGE DATA for (int yy = 0; yy < 4; yy++) { byte b = 0; byte pow = 1; for (int xx = 0; xx < 4; xx++) { Color coll = img.GetPixel(x * 4 + xx, y * 4 + yy); byte col; if (coll.A < 128) { col = 3; } else { col = (byte)ImageIndexer.closest(coll, palettes[paletteNumbers[x, y]]); if (col == 3) { col = 2; } } b |= (byte)(pow * col); pow *= 4; } texDat.writeByte(b); } //WRITE THE FORMAT-5 SPECIFIC DATA ushort dat = (ushort)(newPalNums[paletteNumbers[x, y]] * 2); if (!hasTransparent || !ContainsTransparent(img)) { dat |= 2 << 14; } f5Dat.writeUShort(dat); } f5data = f5Dat.getArray(); texdata = texDat.getArray(); }*/ public ImageTexeler(Bitmap img, int paletteMaxNum, ref System.ComponentModel.BackgroundWorker bw, bool color2 = false) { this.color2 = false; color2 = false; //this.color2 = color2; //bool trans = true;//ContainsTransparent(img); Bitmap im = new Bitmap(img.Width, img.Height, System.Drawing.Imaging.PixelFormat.Format64bppPArgb); using (Graphics gr = Graphics.FromImage(im)) { gr.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.None; gr.InterpolationMode = System.Drawing.Drawing2D.InterpolationMode.NearestNeighbor; gr.PixelOffsetMode = System.Drawing.Drawing2D.PixelOffsetMode.HighQuality; gr.CompositingQuality = System.Drawing.Drawing2D.CompositingQuality.HighQuality; gr.DrawImage(img, 0, 0); } this.img = im; LockBitmap iii = new LockBitmap(img); iii.LockBits(); int tx = img.Width / 4; int ty = img.Height / 4; palettes = new List<Color[]>();//[tx * ty][]; paletteCounts = new List<int>();//new int[tx * ty]; paletteNumbers = new int[tx, ty]; paletteDiffs = new float[tx * ty, tx * ty]; double add = 18d / (double)(tx * ty); double Progress = 10; int palNum = 0; double percent = 0; double add2 = 100d / (double)(tx * ty); for (int x = 0; x < tx; x++) for (int y = 0; y < ty; y++) { Bitmap ni = new Bitmap(4, 4/*, System.Drawing.Imaging.PixelFormat.Format16bppRgb555*/); /*using (Graphics gr = Graphics.FromImage(ni)) { //gr.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.HighQuality; //gr.InterpolationMode = System.Drawing.Drawing2D.InterpolationMode.HighQualityBicubic; //gr.PixelOffsetMode = System.Drawing.Drawing2D.PixelOffsetMode.HighQuality; //gr.CompositingQuality = System.Drawing.Drawing2D.CompositingQuality.HighQuality; gr.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.None;//.AntiAlias; gr.InterpolationMode = System.Drawing.Drawing2D.InterpolationMode.NearestNeighbor; gr.PixelOffsetMode = System.Drawing.Drawing2D.PixelOffsetMode.HighQuality; gr.CompositingQuality = System.Drawing.Drawing2D.CompositingQuality.HighQuality; gr.DrawImage(this.img, new Rectangle(0, 0, 4, 4), new Rectangle(x * 4, y * 4, 4, 4), GraphicsUnit.Pixel); }*/ LockBitmap nn = new LockBitmap(ni); nn.LockBits(); bool haveTransparent = false; for (int x1 = 0; x1 < 4; x1++) for (int y1 = 0; y1 < 4; y1++) { Color c = iii.GetPixel(x * 4 + x1, y * 4 + y1); nn.SetPixel(x1, y1, c); if (c.A < 128) { haveTransparent = true; //goto end; } } //end: nn.UnlockBits(); List<Color> pal1 = new List<Color>(); pal1.AddRange(ImageIndexer.createPaletteForImage(ni, 4, haveTransparent)); //if(haveTransparent){pal1.Add(Color.Transparent);} Color[] pal = pal1.ToArray(); //ImageIndexer.createPaletteForImage(ni, 4, false); transparentToTheEnd(pal); //if (haveTransparent) //{ // pal[0] = Color.Transparent; //} //ImageIndexerFast iif = new ImageIndexerFast(img, x * 4, y * 4); int con = contains(palettes.ToArray(), pal); if (con != -1) { paletteNumbers[x, y] = con; //paletteCounts.Add(1); } else { palettes.Add(pal);//[palNum] = pal;//iif.palette; paletteNumbers[x, y] = palettes.Count - 1; paletteCounts.Add(1);//[palNum] = 1; calcPaletteDiffs(palettes.Count - 1); } //int similar = calcPaletteDiffs(palNum); // if (similar != -1) // { // paletteCounts[palNum] = 0; // paletteCounts[similar]++; // paletteNumbers[x, y] = similar; // } palNum++; Progress += add; bw.ReportProgress((int)Progress, "Generating Picture " + percent.ToString("000") + "%"); percent += add2; if (bw.CancellationPending) { bw.ReportProgress(0, "Canceled"); return; } } percent = 0; add2 = 100d / (((double)countUsedPalettes() - (double)paletteMaxNum)); add = 74d / (((double)countUsedPalettes() - (double)paletteMaxNum)); //double iw = 0; while (countUsedPalettes() > paletteMaxNum) { //iw += 1; //Console.Out.WriteLine(countUsedPalettes()); int besta = -1; int bestb = -1; float bestDif = float.MaxValue; //Find the two most similar palettes for (int i = 0; i < palettes.Count; i++) { if (paletteCounts[i] == 0) continue; for (int j = 0; j < palettes.Count; j++) { if (i == j) continue; if (paletteCounts[j] == 0) continue; if (paletteDiffs[i, j] < bestDif) { bestDif = paletteDiffs[i, j]; besta = j; bestb = i; } } } //Merge the Palettes!!! palettes[besta] = palMerge(palettes[besta], palettes[bestb]); calcPaletteDiffs(besta); paletteCounts[besta] += paletteCounts[bestb]; paletteCounts[bestb] = 0; for (int x = 0; x < tx; x++) for (int y = 0; y < ty; y++) if (paletteNumbers[x, y] == bestb) paletteNumbers[x, y] = besta; Progress += add; percent += add2; bw.ReportProgress((int)Progress, "Generating Palette " + percent.ToString("000") + "%"); if (bw.CancellationPending) { bw.ReportProgress(0, "Canceled"); return; } } //CREATE THE FINAL PAL int currNum = 0; finalPalette = new Color[countUsedPalettes() * 4]; int[] newPalNums = new int[palettes.Count]; for (int i = 0; i < palettes.Count; i++) { if (paletteCounts[i] != 0) { transparentToTheEnd(palettes[i]);// newPalNums[i] = currNum; Array.Copy(palettes[i], 0, finalPalette, currNum * 4, 4); currNum++; } } ByteArrayOutputStream texDat = new ByteArrayOutputStream(); ByteArrayOutputStream f5Dat = new ByteArrayOutputStream(); for (int y = 0; y < ty; y++) for (int x = 0; x < tx; x++) { //Find out if texel has transparent. bool hasTransparent = false; for (int yy = 0; yy < 4; yy++) for (int xx = 0; xx < 4; xx++) { Color coll = iii.GetPixel(x * 4 + xx, y * 4 + yy); if (coll.A < 128) { hasTransparent = true; goto End; } } End: //WRITE THE IMAGE DATA for (int yy = 0; yy < 4; yy++) { byte b = 0; byte pow = 1; for (int xx = 0; xx < 4; xx++) { Color coll = iii.GetPixel(x * 4 + xx, y * 4 + yy); byte col; if (coll.A < 128) { col = 3; } else { List<Color> colo = new List<Color>(); colo.AddRange(palettes[paletteNumbers[x, y]]); if (hasTransparent) { colo.RemoveAt(3); } col = (byte)ImageIndexer.closest(coll, colo.ToArray()); //if (col == 3) { col = 2; } } b |= (byte)(pow * col); pow *= 4; } texDat.writeByte(b); } //WRITE THE FORMAT-5 SPECIFIC DATA ushort dat = (ushort)(newPalNums[paletteNumbers[x, y]] * 2); if (!hasTransparent/* || !ContainsTransparent(img)*/) { dat |= 2 << 14; } f5Dat.writeUShort(dat); } iii.UnlockBits(); f5data = f5Dat.getArray(); texdata = texDat.getArray(); }
private static void DoAnimation() { //return; //WaveTimer.Enabled = false; if (centroids.Count == 0 || Form1.spellText != "") { //LogitechGSDK.LogiLedSetLighting(0, 0, 0); //WaveTimer.Enabled = true; if (Form1.spellText == "" && Form1.useLogitechColours && ((bw_Keysave != null && !bw_Keysave.IsBusy) || (bw_Breathe != null && !bw_Breathe.IsBusy) || (bw_Breathe == null && bw_Keysave == null)) && isAnimated) { //LogitechGSDK.LogiLedSetLighting(0, 0, 0); LogitechGSDK.LogiLedRestoreLighting(); } isAnimated = false; return; } else { isAnimated = true; //calculate the 2 end point colours into LAB space //System.Drawing.Color c1 = Form1.m_startColour; //System.Drawing.Color c2 = Form1.m_endColour; int fadespeed = Form1.m_fadespeed; int gradientspeed = Form1.m_gradientspeed; //ColorManagment.ColorConverter Converter = new ColorManagment.ColorConverter(); //create a new instance of a ColorConverter //ColorRGB rgb1 = new ColorRGB(RGBSpaceName.sRGB, c1.R , c1.G, c1.B ); //create an RGB color //ColorLab lab1 = Converter.ToLab(rgb1); //ColorRGB rgb2 = new ColorRGB(RGBSpaceName.sRGB, c2.R , c2.G, c2.B ); //create an RGB color //ColorLab lab2 = Converter.ToLab(rgb2); //bmp = new Bitmap(21, 6); ColorLab[,] lab1 = new ColorLab[21, 6]; ColorLab[,] lab2 = new ColorLab[21, 6]; for (int x = 0; x < 21; x++) for (int y = 0; y < 6; y++) { distances[x, y] = double.MaxValue; times[x, y] = int.MaxValue; } for (int i = 0; i < centroids.Count; i++) { centroid c = centroids[i]; for (int x = 0; x < 21; x++) for (int y = 0; y < 6; y++) { double distance = Math.Sqrt(((x - c.point.X) * (x - c.point.X) + (y - c.point.Y) * (y - c.point.Y))); distance = Math.Abs(distance) / (Form1.m_distanceFalloff / 2); if (Form1.m_Wave) { distance -= c.countup; distance = Math.Abs(distance); } if ((distance + c.countup) < (Math.Abs(distances[x, y] + times[x,y]))) { distances[x, y] = distance; lab1[x, y] = c.lab1; lab2[x, y] = c.lab2; if (c.countup / 20.0 < times[x, y]) times[x, y] = c.countup / 20.0; } } c.countup++; centroids[i] = c; } bool allBlack = true; try { //bmp = new Bitmap(21, 6); LockBitmap lockBitmap = new LockBitmap(bmp); lockBitmap.LockBits(); for (int x = 0; x < 21; x++) for (int y = 0; y < 6; y++) { double distance = distances[x, y]; System.Drawing.Color colour = System.Drawing.Color.White; if (Form1.m_Wave == true) colour = getColour(lab1[x, y], lab2[x, y], distance + times[x, y] + Math.Pow(distance, Form1.m_WaveSpeed), gradientspeed, fadespeed); else colour = getColour(lab1[x, y], lab2[x, y], distance + times[x, y], gradientspeed, fadespeed * 10); lockBitmap.SetPixel(x, y, colour); if (allBlack && (colour.R > 0 || colour.G > 0 || colour.B > 0)) allBlack = false; } lockBitmap.UnlockBits(); } catch { } finally { } byte[] b = Form1.getLEDGridFromBitmap(bmp); //((Form1)Application.OpenForms[0]).pic1.Image = bmp; //bmp.Save(@"C:\temp\heatmap.png"); Debug.WriteLine("set lighting at " + DateTime.Now.Minute.ToString() + ":" + DateTime.Now.Minute.ToString() + ":" + DateTime.Now.Second.ToString() + ":" + DateTime.Now.Millisecond.ToString()); LogitechGSDK.LogiLedSetLightingFromBitmap(b); if (allBlack) { centroids.Clear(); } else if (!Form1.m_Wave) { for (int i = centroids.Count - 1; i >= 0; i--) { try { if (centroids[i].countup / 10 > 255 / fadespeed) centroids.RemoveAt(i); } catch { } } } // System.Threading.Thread.Sleep(Form1.m_AnimationSpeed); } //WaveTimer.Enabled = true; }
public Color[] palMerge(Color[] a, Color[] b) { //return a; //FIXME!!!! //Very ugly hack here. I put the 8 colors in a bitmap //and let ImageIndexer find me a good 4-color palette :P bool trans = false; Bitmap bi = new Bitmap(8, 1); LockBitmap iii = new LockBitmap(bi); iii.LockBits(); for (int i = 0; i < 4; i++) { iii.SetPixel(i, 0, a[i]); iii.SetPixel(i + 4, 0, b[i]); if (b[i] == Color.Transparent || a[i] == Color.Transparent) { trans = true; } } iii.UnlockBits(); List<Color> pal1 = new List<Color>(); //if (!color2) //{ pal1.AddRange(ImageIndexer.createPaletteForImage(bi, 4, trans));//(trans ? 3 : 4), false)); //} ///else //{ // pal1.AddRange(ImageIndexer.createPaletteForImage(bi, 2, trans));//(trans ? 3 : 4), false)); // pal1.AddRange(new Color[2]); //} //if (trans) { pal1.Add(Color.Transparent); } Color[] pal = pal1.ToArray(); transparentToTheEnd(pal); return pal; //Haha, it was too slow :) /*Color[] pal = new Color[4]; int one = 0; int two = 0; for (int i = 0; i < a.Length; i++) { int tdiff = (b[i].R - a[i].R) + (b[i].G - a[i].G) + (b[i].B - a[i].B); if (tdiff == 0) one++; else if (tdiff < 0) two++; else { two++; } } return one >= two ? a : b;*/ }
void bw_Keysave_DoWork(object sender, DoWorkEventArgs e) { LogitechGSDK.LogiLedSetLighting(0, 0, 0); DateTime inittime = DateTime.Now; int counter = 0; List<keysavePoint> points = new List<keysavePoint> { }; Random rnd = new Random(); while (true) { if (bw_Keysave.CancellationPending) return; TimeSpan elapsed = DateTime.Now - inittime; if (elapsed.TotalMilliseconds > 500) //change this namber to change speed new stars appear { //for (int c = 0; c < 2; c++) //{ int newx = rnd.Next(0,20); int newy = rnd.Next(0, 5); keysavePoint kp = new keysavePoint(); kp.point = new Point(newx, newy); kp.counter = 0; points.Add(kp); //} //Console.Write("."); inittime = DateTime.Now; } if (counter > 4) //change this number to change speed stars change { counter = 0; System.Drawing.Color c1 = Form1.m_startColour; System.Drawing.Color c2 = Form1.m_endColour; int fadespeed = Form1.m_fadespeed; int gradientspeed = Form1.m_gradientspeed; ColorManagment.ColorConverter Converter = new ColorManagment.ColorConverter(); //create a new instance of a ColorConverter ColorRGB rgb1 = new ColorRGB(RGBSpaceName.sRGB, c1.R, c1.G, c1.B); //create an RGB color ColorLab lab1 = Converter.ToLab(rgb1); ColorRGB rgb2 = new ColorRGB(RGBSpaceName.sRGB, c2.R, c2.G, c2.B); //create an RGB color ColorLab lab2 = Converter.ToLab(rgb2); bmp = new Bitmap(21, 6); LockBitmap lockBitmap = new LockBitmap(bmp); lockBitmap.LockBits(); for (int x = 0; x < 21; x++) for (int y = 0; y < 6; y++) { distances[x, y] = double.MaxValue; times[x, y] = int.MaxValue; } for (int i = 0; i < points.Count; i++) { keysavePoint c = points[i]; for (int x = 0; x < 21; x++) for (int y = 0; y < 6; y++) { double distance = Math.Sqrt(((x - c.point.X) * (x - c.point.X) + (y - c.point.Y) * (y - c.point.Y))); distance = Math.Abs(distance) / (Form1.m_distanceFalloff / 2); if (Form1.m_Wave) { distance -= c.counter; distance = Math.Abs(distance); } if (distance < Math.Abs(distances[x, y])) { distances[x, y] = distance; } if (c.counter < times[x, y]) times[x, y] = c.counter; } c.counter++; points[i] = c; } for (int x = 0; x < 21; x++) for (int y = 0; y < 6; y++) { double distance = distances[x, y]; System.Drawing.Color colour = System.Drawing.Color.White; if (Form1.m_Wave == true) colour = getColour(lab1, lab2, distance + times[x, y] + Math.Pow(distance, Form1.m_WaveSpeed), gradientspeed, fadespeed); else colour = getColour(lab1, lab2, distance + times[x, y], gradientspeed, fadespeed); lockBitmap.SetPixel(x, y, colour); } for (int k = points.Count - 1; k >= 0; k--) { if (points[k].counter > 20) points.RemoveAt(k); } lockBitmap.UnlockBits(); byte[] b = Form1.getLEDGridFromBitmap(bmp); //((Form1)Application.OpenForms[0]).pic1.Image = bmp; //bmp.Save(@"C:\temp\heatmap.png"); LogitechGSDK.LogiLedSetLightingFromBitmap(b); } counter++; System.Threading.Thread.Sleep(10); } }