you are here: Skip Navigation Linkshome > blog

HostingAbc Logo

Show all posts.
I was wondering how to save small bitmaps programmatically of websites so I can show a gallery of these web pages on an ASP.Net page.

Obviously the first step in achieving it is to use a webbrowser control in .NET and to navigate to the specified webpage.
The second step would be to copy the image from the web browser's window to our own Bitmap using the BitBlt WinAPI method and the last step would be to save this bitmap somewhere on the file system or maybe a database.

So let's see the method which captures the content of a web browser window and saves it to a Bitmap object:

C#
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
private Bitmap CaptureBrowserImage(WebBrowser browser)
{
    Bitmap resultBitmap = new Bitmap(browser.Width, browser.Height);
    Graphics g = Graphics.FromImage(resultBitmap);

    IntPtr hdcSrc = GetWindowDC(browser.Handle);
    IntPtr hdcDest = g.GetHdc();

    BitBlt(hdcDest, 0, 0, browser.Width, browser.Height, hdcSrc, 0, 0,
        (uint)TernaryRasterOperations.SRCCOPY);

    g.ReleaseHdc(hdcDest);
    ReleaseDC(browser.Handle, hdcSrc);

    return resultBitmap;
}


It might also be possible to use the StretchBlt WinAPI method to generate a smaller image, but I just wanted to save the image as it is - later on I will be able to generate thumbnails out of the saved images if I want to.

(big thanks to András for the ideea and help on using BitBlt)
add linkThe last comments:moszinet says:amugy: bluetooth, wifi van, irda nincs. 13.3 inches trubright kepernyo, 1 SD kartyaolvaso, taska nincs, eger normalis usb (ize .. csunya fekete ...), dvd iro van, floppy nincs. 150e ft -ot kerek erte. toshiba U30011V - novemberben vettem, nemzetkX says:mi van még rajta? bluetooth, irda, wifi? milyen a képernyő? kártyaolvasók; hány darab mit lehet beledugni? táska; egér; milyen színű? ugye van rajta dvd író? floppy? mennyit kérsz értgaba says:tök jó tipp, köszi, ez még jól jöehet! meken annyival egyszerűbb, hogy az address bookban eleve vannak csoportok, és azzal szinkronizálmoszinet says:eaposztrof: szerintem nem érdemes flash-re alapozni - sem java-ra. Ha megnézed a mobil alkalmazások zöme native. Standard UI, megszokott kezelhetőség. Nekem legalábbis ezek számítanak.Sanyi.NET says:You are now being upgraded from TRAITOR to ARCHITRAITOR. Congratulations! +10 skill points to SNOBBERY and +5 skill point to MAC_ADDICT. :))eaposztrof says:nem kell.. ime egy post ahonnan tovabb informalodhatsz a temaban: http://blog.meetup.hu/2008/10/23/novemberi-videok/ minden iphone kepes flasht futtatni, erre erdemes alapozni..Sanyi.NET says:nem csak áruló, hanem bűnöző is! telefonokat feltörtni - bűncselekmény!!! amugy tök jó teló :)))))))))
Copyright (C) 2003, Molnar Szilveszter m@il me
Sofisto, egypt, egipt, egyiptom, moszi, Molnar Szilveszter, Moszi, pagina personala, weboldal, aswan, cairo, piramide, pyramid, piramis, piramisok, auto, masina, opel corsa, sfantu gheorghe, sepsiszentgyorgy, st george, saint george, timisoara, romania, ungaria, Kefren, temesvar, magyarorszag, hungary, Chefren, Cheops, Keops, SMS, HURGHADA, Kartago Tours, photo, digital,