private void pictureBox1_MouseDown(object sender, MouseEventArgs e) { Color c; int x1 = e.X - 1; int x2 = e.X + 1; using (BitmapDecorator deco = new BitmapDecorator(window.ProgressBindings.Screenshot)) { c = deco.GetPixel(e.X, e.Y); int x_next = x1 - 1; Color x_color = deco.GetPixel(x1, e.Y); Color x_next_color = deco.GetPixel(x_next, e.Y); while (isLineContinue(c, x_color, x_next_color) && x_next > 0) { x_color = x_next_color; x1 = x_next--; x_next_color = deco.GetPixel(x_next, e.Y); } x_next = x2 + 1; x_color = deco.GetPixel(x2, e.Y); x_next_color = deco.GetPixel(x_next, e.Y); while (isLineContinue(c, x_color, x_next_color) && x_next < window.ProgressBindings.Screenshot.Width) { x_color = x_next_color; x2 = x_next++; x_next_color = deco.GetPixel(x_next, e.Y); } } int selected = clbWho.SelectedIndex; window.ProgressBindings.Progresses[selected].Extend(x1, x2, e.Y); c = window.ProgressBindings.Screenshot.GetPixel(e.X, window.ProgressBindings.Progresses[selected].Y1); window.ProgressBindings.Progresses[selected].HpColor = c; listBox1.Items.Add(c); displayMark(selected); }
/// <summary> /// Сохранение скриншота из буффера библиотеки в локальный битмап /// </summary> /// <param name="bitmap"></param> public void AssignBitmapFromBytes(byte[] bitmap) { using (MemoryStream s = new MemoryStream(bitmap)) { using (BinaryReader br = new BinaryReader(s)) { tagBITMAPFILEHEADER bmpFileHeader = new tagBITMAPFILEHEADER(); bmpFileHeader.bfType = br.ReadUInt16(); bmpFileHeader.bfSize = br.ReadUInt32(); bmpFileHeader.bfReserved1 = br.ReadUInt16(); bmpFileHeader.bfReserved2 = br.ReadUInt16(); bmpFileHeader.bfOffBits = br.ReadUInt32(); tagBITMAPINFOHEADER bmpInfoHeader = new tagBITMAPINFOHEADER(); bmpInfoHeader.bV5Size = br.ReadUInt32(); bmpInfoHeader.bV5Width = br.ReadInt32(); bmpInfoHeader.bV5Height = br.ReadInt32(); bmpInfoHeader.bV5Planes = br.ReadUInt16(); bmpInfoHeader.bV5BitCount = br.ReadUInt16(); bmpInfoHeader.bV5Compression = br.ReadUInt32(); bmpInfoHeader.bV5SizeImage = br.ReadUInt32(); bmpInfoHeader.bV5XPelsPerMeter = br.ReadInt32(); bmpInfoHeader.bV5YPelsPerMeter = br.ReadInt32(); bmpInfoHeader.bV5ClrUsed = br.ReadUInt32(); bmpInfoHeader.bV5ClrImportant = br.ReadUInt32(); if ( Screenshot.Width != bmpInfoHeader.bV5Width || Screenshot.Height != bmpInfoHeader.bV5Height ) { Screenshot = new Bitmap(bmpInfoHeader.bV5Width, bmpInfoHeader.bV5Height, PixelFormat.Format24bppRgb); } int px_size = (int)(bmpFileHeader.bfSize - bmpFileHeader.bfOffBits) / (bmpInfoHeader.bV5Width * bmpInfoHeader.bV5Height); Color pc; UInt16 pcs16; UInt32 pcs32; byte a, r, g, b; using (BitmapDecorator bd = new BitmapDecorator(Screenshot)) { for (int y = 0; y < bmpInfoHeader.bV5Height; ++y) { for (int x = 0; x < bmpInfoHeader.bV5Width; ++x) { switch (px_size) { case 2: // 16 bit pcs16 = br.ReadUInt16(); //byte r = (byte) (c << 10); //byte g = (byte) (c << 5); //byte b = (byte) c; r = (byte)((pcs16 & 0xf800) >> 11); g = (byte)((pcs16 & 0x07e0) >> 5); b = (byte)(pcs16 & 0x001f); r = (byte)(r << 3); g = (byte)(g << 2); b = (byte)(b << 3); pc = Color.FromArgb(r, g, b); break; case 4: // 32 bit pcs32 = br.ReadUInt32(); //byte r = (byte) (c << 10); //byte g = (byte) (c << 5); //byte b = (byte) c; a = (byte)(pcs32 >> 24); r = (byte)(pcs32 >> 16); g = (byte)(pcs32 >> 8); b = (byte)pcs32; pc = Color.FromArgb(a, r, g, b); break; default: pc = Color.Black; break; } bd.SetPixel( x, bmpInfoHeader.bV5Height - y - 1, pc ); } } } } } }