public bool FindImagePositionOnScreen() { // StatusTextBox.Text = "Wrong Bytes. Searching..."; Basic.CaptureImage(ref screenBitmap); Basic.GetImageBytes(ref screenBytes, screenBitmap); // Try to find prefix image without blank pixels. var index = JocysCom.ClassLibrary.Text.Helper.IndexOf(screenBytes, ColorPrefixBytes); // If not found then try to find with blank pixels. var havePixelSpaces = false; if (index < 0) { index = JocysCom.ClassLibrary.Text.Helper.IndexOf(screenBytes, ColorPrefixBytesBlanked); havePixelSpaces = index > -1; } if (SettingsManager.Options.DisplayMonitorHavePixelSpaces != havePixelSpaces) { SettingsManager.Options.DisplayMonitorHavePixelSpaces = havePixelSpaces; } // StatusTextBox.Text = string.Format("Pixel Index {0}...", index); if (index > -1) { var screen = System.Windows.Forms.Screen.PrimaryScreen; var sw = screen.Bounds.Width; var sh = screen.Bounds.Height; // Get new coordinates of image. var pixelIndex = index / 3; // 3 bytes per pixel. var newX = pixelIndex % sw; var newY = (pixelIndex - newX) / sw; SettingsManager.Options.DisplayMonitorPositionX = newX; SettingsManager.Options.DisplayMonitorPositionY = newY; //StatusTextBox.Text += string.Format(" [{0}:{1}]", x, y); } return(index > -1); }
/// <summary> /// Image: prefix[6] + change[1] + size[1] + message_bytes /// </summary> public void CaptureTextFromPosition(out int change, out string message, Screen screen) { change = 0; message = null; if (screen == null) { return; } var x = SettingsManager.Options.DisplayMonitorPositionX; var y = SettingsManager.Options.DisplayMonitorPositionY; var sw = screen.Bounds.Width; var sh = screen.Bounds.Height; // Make sure take pixel pairs till the end of the line. var length = sw - x; length = length - (length % 2); // Take screenshot of the line. Basic.CaptureImage(ref lineBitmap, screen.Bounds.X + x, screen.Bounds.Y + y, length, 1); // var asm = new JocysCom.ClassLibrary.Configuration.AssemblyInfo(); // var path = asm.GetAppDataPath(false, "Images\\Screen_{0:yyyyMMdd_HHmmss_fff}.png", DateTime.Now); // lineBitmap.Save(path, ImageFormat.Png); Basic.GetImageBytes(ref lineBytes, lineBitmap); var prefixBytes = SettingsManager.Options.DisplayMonitorHavePixelSpaces ? ColorPrefixBytesBlanked : ColorPrefixBytes; var index = JocysCom.ClassLibrary.Text.Helper.IndexOf(lineBytes, prefixBytes); // If not found then... if (index == -1) { return; } // StatusTextBox.Text += string.Format("Prefix found"); if (SettingsManager.Options.DisplayMonitorHavePixelSpaces) { RemoveBlankPixels(lineBytes, ref lineBufferNoBlanks); } else { lineBufferNoBlanks = lineBytes; } var prefix = ColorPrefixBytes; // Skip prefix. var ms = new MemoryStream(lineBufferNoBlanks, prefix.Length, lineBufferNoBlanks.Length - prefix.Length); var br = new System.IO.BinaryReader(ms); change = ReadRgbInt(br); var messageSize = ReadRgbInt(br); var messageBytes = new byte[messageSize]; br.Read(messageBytes, 0, messageSize); message = System.Text.Encoding.UTF8.GetString(messageBytes); br.Dispose(); }
/// <summary> /// Image: prefix[6] + change[1] + size[1] + message_bytes /// </summary> public void CaptureTextFromPosition(out int change, out string message) { change = 0; message = null; var x = SettingsManager.Options.DisplayMonitorPositionX; var y = SettingsManager.Options.DisplayMonitorPositionY; var screen = System.Windows.Forms.Screen.PrimaryScreen; var sw = screen.Bounds.Width; var sh = screen.Bounds.Height; // Make sure take pixel pairs till the end of the line. var length = sw - x; length = length - (length % 2); // Take screenshot of the line. Basic.CaptureImage(ref lineBitmap, x, y, length, 1); Basic.GetImageBytes(ref lineBytes, lineBitmap); var prefixBytes = SettingsManager.Options.DisplayMonitorHavePixelSpaces ? ColorPrefixBytesBlanked : ColorPrefixBytes; var index = JocysCom.ClassLibrary.Text.Helper.IndexOf(lineBytes, prefixBytes); // If not found then... if (index == -1) { return; } // StatusTextBox.Text += string.Format("Prefix found"); if (SettingsManager.Options.DisplayMonitorHavePixelSpaces) { RemoveBlankPixels(lineBytes, ref lineBufferNoBlanks); } else { lineBufferNoBlanks = lineBytes; } var prefix = ColorPrefixBytes; // Skip prefix. var ms = new MemoryStream(lineBufferNoBlanks, prefix.Length, lineBufferNoBlanks.Length - prefix.Length); var br = new System.IO.BinaryReader(ms); change = ReadRgbInt(br); var messageSize = ReadRgbInt(br); var messageBytes = new byte[messageSize]; br.Read(messageBytes, 0, messageSize); message = System.Text.Encoding.UTF8.GetString(messageBytes); br.Dispose(); }
private void CaptureScreenAndSave_Click(object sender, EventArgs e) { var screen = ((KeyValue <Screen, string>)ScreensList.SelectedItem).Key; byte[] screenBytes = null; Bitmap screenBitmap = null; Basic.CaptureImage(ref screenBitmap, screen); Basic.GetImageBytes(ref screenBytes, screenBitmap); var asm = new AssemblyInfo(); var path = asm.GetAppDataPath(false, "Images\\Screen_{0:yyyyMMdd_HHmmss_fff}.png", DateTime.Now); var fi = new System.IO.FileInfo(path); if (!fi.Directory.Exists) { fi.Directory.Create(); } screenBitmap.Save(path, System.Drawing.Imaging.ImageFormat.Png); ControlsHelper.OpenPath(fi.Directory.FullName); }