views:

418

answers:

3

Hi, how can I render a part of website to a bitmap using delphi?

recently I've seen Raudus framework which is ExtJs binding/wrapper for delphi. However what is unique about that, it does render components to look exactly like in the browser. Simply, it works like kind of WYSIWYG designer for Javascript components in delphi IDE. I was unable to try it since I'm using delphi personal (it requires dbrtl). However looking on the demo movie it takes some time to render the components (even after resizing them), thus I believe it is rendered through web browser rendering engine or something similar...

if anyone knows something similar but open sourced, please let me know... thanks in advance, m

A: 

If you're cool with how Internet Explorer renders the page, it will show properly in the TWebBrowser (built in component), and you can generate bitmaps from there.

http://delphi.about.com/od/vclusing/a/wb_scren_shot.htm

http://www.delphi3000.com/articles/article_4132.asp?SK=

Bruce McGee
There is a TWebBrowser equivalent for Firefox called Mozilla Firefox ActiveX.
HalloDu
@HalloDu: AFAICT, that ActiveX only works in early (v1.5 and maybe 2.x) of FireFox. That makes it too version dependent IMO; you'd have to require the user to install one of the specific versions with which it works. IE, OTOH, you can count on to be installed in some flavor on every system.
Ken White
Yes, but depending on which version, he might have trouble using that at design time in Delphi Personal.
Bruce McGee
its D7 PE, I know both Mozilla and IE ActiveX. It's better to use IE here since it doesn't require Firefox to be installed.Thank you for those links, I'll try them...
migajek
A: 

Dave Baldwin's HTML display components are now freeware with source (even the Professional version) and work in Delphi up to 2006 (which means also 2007). I don't know if those will help, since you didn't specify which version of Delphi you're using.

Ken White
Delphi version doesn't really matter here. They work under D7 as well, I know those components. However it doesn't help here, since it must be displayed with JavaScript enabled.
migajek
I did mention "up to 2006", which would include D7. Also, the version matters if you're using Delphi 2009 or 2010, which are not supported, in which case the recommendation would have been worthless. :-) Which is why I mentioned it in the first place - especially since the release of 2009 (Unicode only), the version can make a difference, just like an answer which uses generics or the new improved D2010 RTTI would be useless to someone using D7.
Ken White
I'm sorry Ken, I just missed "up" when reading ...
migajek
+2  A: 

A while ago I discovered an arcane ActiveX call: OleDraw. As it turns out, it works just great to use an embedded WebBrowser component (IWebBrowser2) to render HTML and grab the output into a bitmap.

The code may look a little like this:

uses ActiveX, OleCtrls, SHDocVw;
b:=TBitmap.Create;
try
  b.Width:=SizeX;
  b.Height:=SizeY;
  OleDraw(WebBrowser1.OleObject,DVASPECT_CONTENT,b.Canvas.Handle,Rect(0,0,SizeX,SizeY));
  b.SaveToFile(FileName);
finally
  b.Free;
end;
Stijn Sanders