The Cache: Technology Expert's Forum
 
*
Welcome, Guest. Please login or register. July 29, 2010, 07:59:01 PM

Login with username, password and session length


Pages: [1]
  Print  
Author Topic: [c#/dotnet] Get image from webbrowser?  (Read 1357 times)
uriziel
n00b
*
Offline Offline

Posts: 3


View Profile
« on: October 25, 2009, 12:02:23 PM »

Hey guys, I`m new here. Actually, I `ve lurked around for some time.

I`m working on an account creator and I`m using the webbrowser control. My problem is with the captcha. I can parse the captcha link, but with every request, the image changes. So that`s useless..

Is there any way of grabbing the captcha from the webbrowser control?

Thanks for answering!
Logged
perkiset
Olde World Hacker
Administrator
Lifer
*****
Offline Offline

Posts: 8649



View Profile
« Reply #1 on: October 25, 2009, 12:20:04 PM »

This is not my area, so I'd simply like a clarification: are we talking about controlling IE to go get stuff and then you're parsing it?

If you're a C# person isn't there anything that would do this more effectively? Seems like a lot of overhead for that little web call...
Logged

It's the things you learn after you know it all that really count.
-John Wooden
uriziel
n00b
*
Offline Offline

Posts: 3


View Profile
« Reply #2 on: October 25, 2009, 12:30:17 PM »

Hi, thanks for answering!

I use the webbrowser control because I can`t be bothered with cookie control,etc. Yes, I am controlling IE .

The webbrowser has a "Document" property which is a htmldocument that I can parse. The problem is  that once I get the page, I also get the captcha. When I try to read the src of the captcha , I get another image , because it`s always changing!

I can`t do it any other way at the moment. I plan on improving and I will certainly learn more sophisticated methods in the future. But now I really need to get this done this way, because I feel it`s the quickest way.

Thanks for answering!
« Last Edit: October 25, 2009, 12:32:15 PM by uriziel » Logged
nop_90
Global Moderator
Lifer
*****
Offline Offline

Posts: 1866


View Profile
« Reply #3 on: October 25, 2009, 09:53:08 PM »

Copy the image to clipboard

function copyImage(sImgID)
   {
      var ctrlRange = document.body.createControlRange();
      ctrlRange.add(document.all(sImgID));
      ctrlRange.execCommand("Copy");
   }

Then get image from clipboard
Clipboard.GetImage()

It is all done with OLE/COM (or what ever MS calls it now days).
I have no fuking idea how to do it with C#, but those API calls will get u in the right direction.
Logged
uriziel
n00b
*
Offline Offline

Posts: 3


View Profile
« Reply #4 on: October 26, 2009, 05:14:33 AM »

Thanks a lot for the code nop! I also have found a way to do it. Your way is much quicker though.

This is what I did, in case someone is looking for the same answers :

Code:
{
            Bitmap bitmap = new Bitmap(webBrowser1.Width, webBrowser1.Height);
            webBrowser1.DrawToBitmap(bitmap, new Rectangle(new Point(),
            webBrowser1.Size));
            pictureBox1.BackgroundImage = CropBitmap(bitmap, 1, 240, 200, 50);
        }

The code for CropBitmap function :

Code:
public Bitmap CropBitmap(Bitmap bitmap, int cropX, int cropY, int cropWidth, int cropHeight)
        {
            Rectangle rect = new Rectangle(cropX, cropY, cropWidth, cropHeight);
            Bitmap cropped = bitmap.Clone(rect, bitmap.PixelFormat);
            return cropped;
        }


What this does is it goes to the webbrowser , creates a bitmap image of the control , it crops the image and then displays it in the picturebox.
Logged
nop_90
Global Moderator
Lifer
*****
Offline Offline

Posts: 1866


View Profile
« Reply #5 on: October 26, 2009, 05:46:02 AM »

Yah in ur case u are taking a "snapshot" of the browser control.
And then cropping out the image.

That is what i did before i found out about clipboard Smiley
Logged
Pages: [1]
  Print  
 
Jump to:  

Perkiset's Place Home   Best of The Cache   phpMyIDE: MySQL Stored Procedures, Functions & Triggers
Politics @ Perkiset's   Pinkhat's Perspective   
cache
mart
coder
programmers
ajax
php
javascript
Powered by MySQL Powered by PHP Powered by SMF 1.1.2 | SMF © 2006-2007, Simple Machines LLC
Seo4Smf v0.2 © Webmaster's Talks


Valid XHTML 1.0! Valid CSS!