private static void RelicBackgroundWorker_DoWork(object sender, DoWorkEventArgs e) { int WorkerIndex = (int)e.Argument; Bitmap PassedBitmap = Screenshot_Cuts[WorkerIndex]; string FoundText = Module_OCR.OCR_Image(PassedBitmap); e.Result = WorkerIndex + "," + FoundText; if (FoundText.Contains("Forma")) { return; } if (Module_Data.PrimeItemsData.ContainsKey(FoundText)) { Overlay OverlayItem = new Overlay(FoundText, LocationHolder["1920x1080"][Screenshot_Cuts.Count][WorkerIndex]); OverlayHolder.Add(OverlayItem); //_Form_OverlayRelic.Invoke((Action) (()=> { _Form_OverlayRelic.Controls.Add(OverlayItem); })); } else { Debug.Print(FoundText); FlowLayoutPanel TempFLP = new FlowLayoutPanel() { FlowDirection = FlowDirection.TopDown, Margin = new Padding(0, 0, 0, 0), Location = new Point(LocationHolder["1920x1080"][Screenshot_Cuts.Count][WorkerIndex], 32), AutoSize = true }; Label FailLabel = new Label() { Text = string.Format(@"OCR Fail!!! - {0}", FoundText.Replace("&", "&&")), Font = new Font("Microsoft Sans Serif", 10, FontStyle.Bold), MaximumSize = new Size(235, 0), AutoSize = true, BackColor = SystemColors.Control, BorderStyle = BorderStyle.FixedSingle }; PictureBox SomePic = new PictureBox() { BackgroundImage = PassedBitmap, BackgroundImageLayout = ImageLayout.Center, Size = new Size(235, 50), BorderStyle = BorderStyle.FixedSingle }; TempFLP.Controls.AddRange(new Control[] { FailLabel, SomePic }); Form_OverlayRelic._FormReference.BeginInvoke(new Action(() => { Form_OverlayRelic._FormReference.Controls.Add(TempFLP); })); } }
private static string Baro_ReadWindow(ref Bitmap ScreenshotReference, Point StartPoint) { Bitmap BaroItem = new Bitmap(400, 60, PixelFormat.Format24bppRgb); Graphics.FromImage(BaroItem).DrawImage(ScreenshotReference, 0, 0, new Rectangle(StartPoint, BaroItem.Size), GraphicsUnit.Pixel); BitmapData LockedBitmapData = BaroItem.LockBits(new Rectangle(0, 0, BaroItem.Width, BaroItem.Height), ImageLockMode.ReadWrite, BaroItem.PixelFormat); int numBytes = Math.Abs(LockedBitmapData.Stride) * LockedBitmapData.Height; byte[] LockedBitmapBytes = new byte[numBytes]; Marshal.Copy(LockedBitmapData.Scan0, LockedBitmapBytes, 0, numBytes); // Copy the RGB values into the array. int PixelSize = 3; // 24 bits/8 = 3 bytes for (int PixelPosition = 0; PixelPosition < numBytes; PixelPosition += PixelSize) { //RGB is reversed in bytes to BGR int Color_Red = LockedBitmapBytes[PixelPosition + 2]; int Color_Green = LockedBitmapBytes[PixelPosition + 1]; int Color_Blue = LockedBitmapBytes[PixelPosition]; if (Color_Red == TextColour.R && Color_Green == TextColour.G && Color_Blue == TextColour.B) { LockedBitmapBytes[PixelPosition + 2] = 255; LockedBitmapBytes[PixelPosition + 1] = 255; LockedBitmapBytes[PixelPosition] = 255; } else { LockedBitmapBytes[PixelPosition + 2] = 0; LockedBitmapBytes[PixelPosition + 1] = 0; LockedBitmapBytes[PixelPosition] = 0; } } Marshal.Copy(LockedBitmapBytes, 0, LockedBitmapData.Scan0, numBytes); // Copy the RGB values back into bitmap. BaroItem.UnlockBits(LockedBitmapData); //BaroItem.Save("ScreenshotBaroItem_" + DateTime.Now.ToString("*****@*****.**") + ".png", ImageFormat.Png); string BaroResult = Module_OCR.OCR_Image(BaroItem).ToLower(); if (BaroResult.Contains("blueprint")) { BaroResult = BaroResult.Substring(0, BaroResult.IndexOf("blueprint") + "blueprint".Length); } BaroResult = new CultureInfo("en-US", false).TextInfo.ToTitleCase(BaroResult); BaroItem.Dispose(); return(BaroResult); }