PDA

View Full Version : C# download captcha image (geckoFX)



martin0409
09-07-2015, 01:08 AM
need to mothode for download capctcha to disk

i tested


Bitmap bmp = new Bitmap(WindowsImageCreator.GetBitmap(geckoWebBrows er1, 400, 850, 400, 150));
bmp.Save(Application.StartupPath + "\\img1.gif", ImageFormat.Gif);

this is not good for me beacuse captcha in my page , changes place every refresh :/

if u know how to fix pls help me ...thx...


<div id="adcopy-puzzle-image" style="height: 150px; width: 300px; text-align: left;">
<embed id="adcopy-puzzle-image-image" flashvars="url=https://freebitco.in/?op=home&clickTAG=https://api-secure.solvemedia.com/papi/action?c=2@Tw5szIz9haroDwT2alQdXZvD-dgNdDOh@UdmsANdYWdwENU8bgrSwNX9APTC4lJjoHezCUD.IVK VWNpkeY.bfdJ1Py2OznLAX6AroHrvqN3uYJtp6hjetFalkP83W GnhCgiqQo.2qR-J6Q5mFIvhutJ6yPcnS3W1VwLYZJf5l0w7HnxCdW30iGyVC-SNynyUqnMV1Hvlrqvnpb-fYVg3KjvmGk.2MyokUozKxuza2RrcwMjKdLy2t5Bw6yMjCK.Vf 02cZp7qX6Lw6PkrjnBGAllOpbTaj6QbvxGkq3kPX.UPfQUAcc2 Ft7YE4ZwbNAiQoJkhFXIK0uoA&listener=adcopy_media_listener" allowscriptaccess="always" wmode="opaque" style="width:100%;height:100%;padding:0;margin:0;" src="https://api-secure.solvemedia.com/acmedia/f/0/f0I51krdedeMNi/Q/Qkyq.r8drdedfsNs.swf" type="application/x-shockwave-flash">
</div>

EdgarT
09-07-2015, 11:26 AM
foreach (GeckoHtmlElement imgelement in geckoWebBrowser1.Document.GetElementsByTagName("div"))
{
if (imgelement.GetAttribute("id")=="adcopy-puzzle-image")
{
GeckoImageElement ourimgage = (GeckoImageElement)imgelement;
Image ourimg = (System.Drawing.Bitmap)System.Drawing.Image.FromSt ream(new System.IO.MemoryStream(Gecko.Utils.SaveImageElemen t.ConvertGeckoImageElementToPng(geckoWebBrowser1, ourimgage, 0, 0, ourimgage.OffsetWidth, ourimgage.OffsetHeight)));
}
}
This way you should get your image in 'ourimg' var. You can directly load it into picture box or save into disk.

onsali20
09-08-2015, 05:50 PM
Has this been fixed?
I will be more than happy to close this thread on your command.

martin0409
09-14-2015, 12:50 PM
I found this ... working good


public void getsolvemedia(int a, int b)
{

Bitmap bmp = new Bitmap(CreateImage(wb));
Rectangle cropRect = new Rectangle(a, b, 307, 157);
bmp.Save("full.png");
bmp = bmp.Clone(cropRect, bmp.PixelFormat);
Image img = bmp;
img = resizeImage(img, new Size(153, 79));
img.Save("captcha.png");
picture.Image = img;
GeckoInputElement answer = new GeckoInputElement(wb.Document.GetElementsByName("adcopy_response")[0].DomObject);
answer.Value = captcha;
if (captcha.Length >= 2)
{
GeckoButtonElement sub = new GeckoButtonElement(wb.Document.GetElementsByClassN ame("btn btn-warning")[0].DomObject);
sub.Click();
}
}
public static Image resizeImage(Image imgToResize, Size size)
{
return new Bitmap(imgToResize, size);
}
private Image CreateImage(GeckoWebBrowser browser)
{
var w = wb.Document.ActiveElement.ScrollWidth;
var h = wb.Document.ActiveElement.ScrollHeight;

var creator = new ImageCreator(browser);
byte[] imageBytes = creator.CanvasGetPngImage((uint)w, (uint)h);
using (var stream = new MemoryStream(imageBytes))
{
return Image.FromStream(stream);
}
}
public Point GetOffset2(GeckoHtmlElement el)
{
Point pos = new Point(el.OffsetLeft, el.OffsetTop);
GeckoHtmlElement tempEl = el.OffsetParent;
while (tempEl != null)
{
pos.X += tempEl.OffsetLeft;
pos.Y += tempEl.OffsetTop;
tempEl = tempEl.OffsetParent;
}
return pos;
}
var point = GetOffset2(wb.Document.GetHtmlElementById("adcopy-outer"));
var x = point.X;
var y = point.Y;
getsolvemedia(x, y);


or easier methode


using Gecko.Utils;

Point GetScreenCordinates(GeckoHtmlElement obj)
{
Point p = new Point();

try
{
p.X = obj.OffsetLeft;
p.Y = obj.OffsetTop;

GeckoHtmlElement _Parent = obj;
while ((_Parent = _Parent.OffsetParent) != null)
{
p.X += _Parent.OffsetLeft;
p.Y += _Parent.OffsetTop;
}
}
catch { }

return p;
}

private Bitmap GetElementAsImage(GeckoHtmlElement input)
{
Point cords = GetScreenCordinates(input);
return ActiveBrowser.GetBitmap((uint)cords.X, (uint)cords.Y, (uint)input.ClientWidth, (uint)input.ClientHeight);
}
GetElementAsImage((GeckoHtmlElement)ActiveBrowser. Document.GetElementById("adcopy-outer"));



Has this been fixed?
I will be more than happy to close this thread on your command.

Yest ...Solved ....Pls close.... thx for all

EdgarT
09-14-2015, 02:25 PM
http://e.lvme.me/pzv5j7l.jpg