void hook2_KeyPressed(object sender, KeyPressedEventArgs e) { //Form_ImageDetect fi = new Form_ImageDetect(); //fi.Show(); //SendKeys.SendWait("^(c)"); Thread.Sleep(10); SendKeys.Send("^(c)"); strClip2 = Clipboard.GetText().Trim().ToLower(); Clipboard.Clear(); if (strClip2 != "") { Form_PopTranslate pt = new Form_PopTranslate(strClip2); pt.Show(); } else { MessageBox.Show("SCAN NO TEXT !\n Try again!"); } }
private async void SaveToClipboard() { //validate if something selected if (selectWidth > 0) { Rectangle rect = new Rectangle(selectX, selectY, selectWidth, selectHeight); //create bitmap with original dimensions Bitmap OriginalImage = new Bitmap(pictureBox1.Image, pictureBox1.Width, pictureBox1.Height); //create bitmap with selected dimensions Bitmap _img = new Bitmap(selectWidth, selectHeight); //create graphic variable Graphics g = Graphics.FromImage(_img); //set graphic attributes g.InterpolationMode = System.Drawing.Drawing2D.InterpolationMode.HighQualityBicubic; g.PixelOffsetMode = System.Drawing.Drawing2D.PixelOffsetMode.HighQuality; g.CompositingQuality = System.Drawing.Drawing2D.CompositingQuality.HighQuality; g.DrawImage(OriginalImage, 0, 0, rect, GraphicsUnit.Pixel); //insert image stream into clipboard Clipboard.SetImage(_img); } //End application if (Clipboard.ContainsImage() == true) { Image image = (Image)Clipboard.GetDataObject().GetData(DataFormats.Bitmap); image.Save("E:\\A.png", System.Drawing.Imaging.ImageFormat.Png); } else { MessageBox.Show("Clipboard empty."); } this.Hide(); // vipppppp string ImagePath = "E://A.png"; try { HttpClient httpClient = new HttpClient(); httpClient.Timeout = new TimeSpan(1, 1, 1); MultipartFormDataContent form = new MultipartFormDataContent(); form.Add(new StringContent("1ff9c5e13588957"), "apikey"); //Added api key in form data form.Add(new StringContent("eng"), "language"); if (string.IsNullOrEmpty(ImagePath) == false) { byte[] imageData = File.ReadAllBytes(ImagePath); form.Add(new ByteArrayContent(imageData, 0, imageData.Length), "image", "image.jpg"); } HttpResponseMessage response = await httpClient.PostAsync("https://api.ocr.space/Parse/Image", form); string strContent = await response.Content.ReadAsStringAsync(); strContent = strContent.Replace("ParsedText\":\"", "~"); strContent = strContent.Replace("\",\"ErrorMessage", "~"); string[] g = strContent.Split('~'); Form_PopTranslate fp = new Form_PopTranslate(g[1].Replace("\\r\\n", "")); fp.Show(); //MessageBox.Show(g[1].Replace("\\r\\n", "")); //this.Close(); } catch (Exception exception) { MessageBox.Show("Ooops"); } //button2.Enabled = true; this.Close(); }