/// <summary> /// Get a bitmap image, of given size, for the current web page. /// </summary> public Bitmap GetBitmap(int width, int height) { ImageCreator creator = new ImageCreator(this); byte[] mBytes = creator.CanvasGetPngImage((uint)0, (uint)0, (uint)this.Width, (uint)this.Height); return((Bitmap)Bitmap.FromStream(new System.IO.MemoryStream(mBytes))); }
protected override void OnPrint(PaintEventArgs e) { base.OnPrint(e); ImageCreator creator = new ImageCreator(this); byte[] mBytes = creator.CanvasGetPngImage((uint)0, (uint)0, (uint)this.Width, (uint)this.Height); using (Image image = Image.FromStream(new System.IO.MemoryStream(mBytes))) { e.Graphics.DrawImage(image, 0.0f, 0.0f); } }
private Image CreateImage(GeckoWebBrowser browser) { if (_syncControl.InvokeRequired) { return (Image)_syncControl.Invoke(new Func<GeckoWebBrowser, Image>(CreateImage), browser); } #if __MonoCS__ var offscreenBrowser = browser as OffScreenGeckoWebBrowser; Debug.Assert(offscreenBrowser != null); return offscreenBrowser.GetBitmap(browser.Width, browser.Height); #else var creator = new ImageCreator(browser); byte[] imageBytes = creator.CanvasGetPngImage((uint)browser.Width, (uint)browser.Height); // Ensure image is still valid after the MemoryStream closes. using (var stream = new MemoryStream(imageBytes)) { using (var image = new Bitmap(stream)) { return new Bitmap((image)); } } #endif }
private void geckoWebBrowser_DocumentCompleted(object sender, Gecko.Events.GeckoDocumentCompletedEventArgs e) { try { if (STEP == 0) { //On first load STEP = 1; return; } if (TYPE == 1) { if (STEP == -1) { STEP = 1; fillInfoFBReset(); return; } if (STEP == 2) { STEP = 1; var account = (from acc in ACCOUNTS where acc.Used == false select acc).FirstOrDefault(); if (account == null) { lblMsg.Text = "All account are used."; btnRegFB.Text = "Reg FB"; ISSTOP_REG = false; return; } if (!ISSTOP_REG) { TIMER_REG.Interval = 2000; TIMER_REG.Enabled = true; TIMER_REG.Tick += new System.EventHandler(this.timer_Reg_Tick); } geckoWebBrowser.Navigate(URL_REG_FACEBOOK); return; } GeckoDocument document = (GeckoDocument)geckoWebBrowser.Window.Document; GeckoHtmlElement captcha = (GeckoHtmlElement)document.GetElementsByName("captcha_response").FirstOrDefault(); String typeCaptcha = "hidden"; if (captcha != null) typeCaptcha = captcha.GetAttribute("type"); //Fake name GeckoHtmlElement helpFackeName = getGeckoHtmlElementHelp(document); if (helpFackeName != null) { GeckoSelectElement gender = (GeckoSelectElement)document.GetElementById("gender"); Int32 intGender = gender.SelectedIndex; // Gender eGender = Gender.Male; switch (intGender) { case 1: eGender = Gender.Female; break; case 2: eGender = Gender.Male; break; default: break; } GeckoHtmlElement firstName = document.GetElementsByName("firstname").FirstOrDefault(); firstName.SetAttribute("value", NameGenerator.GenerateFirstName(eGender)); GeckoHtmlElement lastName = document.GetElementsByName("lastname").FirstOrDefault(); lastName.SetAttribute("value", NameGenerator.GenerateLastName()); var signup_button = (GeckoInputElement)document.GetElementById("signup_button"); signup_button.Click(); return; } //Captcha if (captcha != null && typeCaptcha != "hidden") { if (ISDECAPTCHA) { ImageCreator imageCreator = new ImageCreator(geckoWebBrowser); GeckoImageElement imgCaptcha = (GeckoImageElement)document.Images[1]; byte[] imageByteArray = imageCreator.CanvasGetPngImage((uint)imgCaptcha.OffsetLeft, (uint)imgCaptcha.OffsetTop, (uint)imgCaptcha.OffsetWidth, (uint)imgCaptcha.OffsetHeight); var submit = (GeckoHtmlElement)document.GetElementsByName("captcha_submit_text").FirstOrDefault(); if (submit == null) submit = (GeckoHtmlElement)document.GetElementById("u_0_0"); Dictionary<string, object> dic = new Dictionary<string, object>(); dic.Add("input", captcha); dic.Add("submit", submit); dic.Add("imageByteArray", imageByteArray); M_CAPTCHA.RunWorkerAsync(dic); return; } captcha.Focus(); return; } //ConfirmCode, invalid GeckoHtmlElement sendConfirmCode = getGeckoHtmlElementSendConfirmCode(document); GeckoHtmlElement invalidElement = getGeckoHtmlElementInvalid(document); if (sendConfirmCode != null || invalidElement != null) { M_RESET.RunWorkerAsync(2); return; } //Submit var submission_request = (GeckoInputElement)document.GetElementsByName("submission_request").FirstOrDefault(); if (submission_request != null) { submission_request.Click(); return; } //Nhập số điện thoại, nhập mã code GeckoHtmlElement inputEx = (GeckoHtmlElement)document.GetElementById("u_0_0"); if (inputEx != null) { String inputClass = inputEx.GetAttribute("class"); String inputName = inputEx.GetAttribute("name"); if (inputClass == "_5whq input") { var submit = getGeckoHtmlElementSubmit(document); if (inputName == "contact_point") { inputEx.SetAttribute("value", PHONE); submit.Click(); return; } else { Dictionary<string, object> dic = new Dictionary<string, object>(); dic.Add("input", inputEx); dic.Add("submit", submit); M_GETCODE.RunWorkerAsync(dic); return; } } } //Nhập mã code GeckoHtmlElement pin = document.GetElementsByName("pin").FirstOrDefault(); if (pin != null) { var submit = (GeckoHtmlElement)document.GetElementsByClassName("btn btnC").FirstOrDefault(); Dictionary<string, object> dic = new Dictionary<string, object>(); dic.Add("input", pin); dic.Add("submit", submit); M_GETCODE.RunWorkerAsync(dic); return; } //Nhập mã code GeckoHtmlElement code = getGeckoHtmlElementCode(document); if (code != null) { var submit = getGeckoHtmlElementSubmit(document); Dictionary<string, object> dic = new Dictionary<string, object>(); dic.Add("input", code); dic.Add("submit", submit); M_GETCODE.RunWorkerAsync(dic); return; } //NextWizard var nextWizard = getGeckoHtmlElementNextWizard(document); if (nextWizard != null) { //Logout var logout = getGeckoHtmlElementLogout(document); if (logout != null) { //Lưu thông tin String cookie = document.Cookie; if (cookie != String.Empty) { String[] arrCookie = cookie.Split(';'); foreach (String cook in arrCookie) { if (cook.Trim().StartsWith("c_user="******"c_user="******"").Trim(); if (fbid != String.Empty) { saveFileFbids(fbid); } break; } } } // updateSatatus(EMAIL, true); // STEP = 2; //logout logout.Click(); return; } else { nextWizard.Click(); return; } } } else if (TYPE == 2) { if (STEP == 10) { //removeCookie(); STEP = 1; var account = (from acc in ACCOUNTS where acc.Done == false select acc).FirstOrDefault(); if (account == null) { lblMsg.Text = "All account invited."; btnLoginFB.Text = "Login FB"; ISSTOP_PLAY = false; return; } if (!ISSTOP_PLAY) { TIMER_PLAY.Interval = 2000; TIMER_PLAY.Enabled = true; TIMER_PLAY.Tick += new System.EventHandler(this.timer_Play_Tick); geckoWebBrowser.Navigate(URL_FACEBOOK); } return; } // GeckoDocument document = (GeckoDocument)geckoWebBrowser.Window.Document; GeckoHtmlElement captcha = (GeckoHtmlElement)document.GetElementsByName("captcha_response").FirstOrDefault(); String typeCaptcha = "hidden"; if (captcha != null) typeCaptcha = captcha.GetAttribute("type"); //Captcha if (captcha != null && typeCaptcha != "hidden") { String idCaptcha = captcha.GetAttribute("id"); String classCaptcha = captcha.GetAttribute("class"); if (idCaptcha == "u_0_0" && classCaptcha == "_5whq input") { //Mã xác nhận var submitSubmit = (GeckoHtmlElement)document.GetElementsByName("submit[Submit]").FirstOrDefault(); Dictionary<string, object> dic = new Dictionary<string, object>(); dic.Add("input", captcha); dic.Add("submit", submitSubmit); M_GETCODE.RunWorkerAsync(dic); } else { //Captcha if (ISDECAPTCHA) { ImageCreator imageCreator = new ImageCreator(geckoWebBrowser); GeckoImageElement imgCaptcha = (GeckoImageElement)document.Images[1]; byte[] imageByteArray = imageCreator.CanvasGetPngImage((uint)imgCaptcha.OffsetLeft, (uint)imgCaptcha.OffsetTop, (uint)imgCaptcha.OffsetWidth, (uint)imgCaptcha.OffsetHeight); var submit = (GeckoHtmlElement)document.GetElementsByName("captcha_submit_text").FirstOrDefault(); if (submit == null) submit = (GeckoHtmlElement)document.GetElementById("u_0_0"); Dictionary<string, object> dic = new Dictionary<string, object>(); dic.Add("input", captcha); dic.Add("submit", submit); dic.Add("imageByteArray", imageByteArray); M_CAPTCHA.RunWorkerAsync(dic); return; } captcha.Focus(); return; } } //photo_input var photoInput = (GeckoHtmlElement)document.GetElementById("photo_input"); if (photoInput != null) { String type = photoInput.GetAttribute("type"); if (type != null && type == "file") { updateDone(EMAIL, true); return; } } //submit[Continue] var submitContinue = (GeckoHtmlElement)document.GetElementsByName("submit[Continue]").FirstOrDefault(); if (submitContinue != null) { submitContinue.Click(); return; } //submit[Okay] var submitOkay = (GeckoHtmlElement)document.GetElementsByName("submit[Okay]").FirstOrDefault(); if (submitOkay != null) { submitOkay.Click(); return; } //Accept play PK if (ISPLAYPK) { var acceptPlay = getGeckoHtmlElementAcceptPlay(document); if (acceptPlay != null) { acceptPlay.Click(); TIMER_ACCEPT.Interval = 2000; TIMER_ACCEPT.Enabled = true; TIMER_ACCEPT.Tick += new System.EventHandler(this.timer_Accept_Tick); return; } String head = document.Head.InnerHtml; String accessToken = getAccessToken(head); if (accessToken != String.Empty) { String url = String.Format("https://graph.facebook.com/v2.2/me?access_token={0}", accessToken); String ret = doGet(url); if (ret != String.Empty) { JToken jToken = JObject.Parse(ret); String fbid = jToken["id"].ToString(); String name = jToken["name"].ToString(); String reqLogin = getDataLogin(fbid, name, accessToken); String urlLogin = String.Format(URLLOGIN, DateTime.Now.ToOADate().ToString()); String retLogin = doPost(urlLogin, reqLogin); JToken jTokenLogin = JObject.Parse(retLogin); String code = jTokenLogin["ErrorCode"].ToString(); lblMsg.Text = String.Format("[PLAY] FBID:{0} Code:{1}", fbid, code); } // STEP = 3; // geckoWebBrowser.Navigate(URL_FACEBOOK); return; } } var logout = getGeckoHtmlElementLogout(document); if (logout != null) { //Đăng nhập thành công if (ISPLAYPK) { if (STEP == 1) { STEP = 2; geckoWebBrowser.Navigate(URL_ACCEPT_PK); return; } else if (STEP == 3) { updateDone(EMAIL, true); STEP = 10; logout.Click(); return; } } else { updateDone(EMAIL, true); STEP = 10; logout.Click(); return; } } } else if (TYPE == 3) { GeckoDocument document = (GeckoDocument)geckoWebBrowser.Window.Document; String head = document.Head.InnerHtml; String accessToken = getAccessToken(head); if (accessToken != String.Empty) { STEP = 3; geckoWebBrowser.Navigate(String.Format(URL_INVITE, accessToken)); return; } if (STEP == 6) { STEP = 1; fillLoginInviteFB(); return; } if (STEP == 3) { GeckoHtmlElement to = getGeckoHtmlElementTo(document); if (to != null) { to.SetAttribute("value", FBIDS); GeckoHtmlElement sendRequest = getGeckoHtmlElementAcceptPlay(document); if (sendRequest != null) { STEP = 4; sendRequest.Click(); return; } } } if (STEP == 4) { STEP = 5; geckoWebBrowser.Navigate(URL_FACEBOOK); return; } var logout = getGeckoHtmlElementLogout(document); if (logout != null) { if (STEP == 1) { STEP = 2; geckoWebBrowser.Navigate(URL_ACCEPT_PK); return; } else if (STEP == 5) { // foreach (Acc acc in ACCOUNTSFB) { if (acc.Email == EMAIL_INVITE) { acc.Done = true; break; } } // STEP = 6; logout.Click(); return; } } } } catch { geckoWebBrowser.Refresh(); } }
public void TakeSnapshot(string location) { try { GeckoWebBrowser wbBrowser = (GeckoWebBrowser)GetCurrentWB(); ImageCreator creator = new ImageCreator(wbBrowser); byte[] rs = creator.CanvasGetPngImage((uint)wbBrowser.Document.ActiveElement.ScrollWidth, (uint)wbBrowser.Document.ActiveElement.ScrollHeight); MemoryStream ms = new MemoryStream(rs); Image returnImage = Image.FromStream(ms); returnImage.Save(location); } catch { } }