ImageEn for Delphi and C++ Builder ImageEn for Delphi and C++ Builder

 

ImageEn Forum
Profile    Join    Active Topics    Forum FAQ    Search this forumSearch
Forum membership is Free!  Click Join to sign-up
Username:
Password:
Save Password
Forgot your Password?

 All Forums
 ImageEn Library for Delphi, C++ and .Net
 ImageEn and IEvolution Support Forum
 Using ImageEnDBView
 New Topic  Reply to Topic
Author Previous Topic Topic Next Topic  

Patrick Quinn

United Kingdom
81 Posts

Posted - Dec 15 2011 :  15:09:10  Show Profile  Reply
I'm trying to capture parts of web pages and store them in a database, using the Delphi 7 TWebBrowser and an ImageEnDBView components.

This following code works, but I am not sure if I am doing things the best way.

I draw the web browser's image on a TBitmap, then assign this to the ImageEnDBView's IO IEBitmap.

procedure CaptureWebPage(const WB: TWebBrowser; const ImageEnDBView: TImageEnDBView); overload;
var
vObj: IViewObject;
r: TRect;
Bmp: TBitmap;
begin
if WB.Document <> nil then
begin
WB.Document.QueryInterface(IViewObject, vObj) ;
if Assigned(vObj) then
try
r := Rect(0, 0, WB.Width, WB.Height);
Bmp := TBitmap.Create;
try
Bmp.Width := WB.Width;
Bmp.Height := WB.Height;
vObj.Draw(DVASPECT_CONTENT, 1, nil, nil, Application.Handle, bmp.Canvas.Handle, @r, nil, nil, 0);

ImageEnDBView.IO.IEBitmap.Assign(Bmp);
ImageEnDBView.IO.Update; // Does not work without this

finally
Bmp.Free;
end;
finally
vObj._Release;
end;
end;
end;

Would it be better to try draw straight on to the IO.IEBitmap, or is this code ok?
Or is there a better way?
Also, I wish to use .png format to store the blob field. I assume I just have to set DatafieldImageFormat to ifPNG?

Thank you

fab

1310 Posts

Posted - Dec 16 2011 :  00:34:19  Show Profile  Reply
You could avoid to use TBitmap drawing the bitmap directly on ImageEnDBView:
ImageEnDBView.IEBitmap.Allocate(WB.Width, WB.Height);
vObj.Draw(DVASPECT_CONTENT, 1, nil, nil, Application.Handle, ImageEnDBView.IEBitmap.Canvas.Handle, @r, nil, nil, 0);
ImageEnDBView.Update();

To save as PNG, yes set DataFieldImageFormat=ifPNG.
Go to Top of Page

Patrick Quinn

United Kingdom
81 Posts

Posted - Dec 16 2011 :  01:53:14  Show Profile  Reply
Thanks, fabrizio.
Go to Top of Page
  Previous Topic Topic Next Topic  
 New Topic  Reply to Topic
Jump To: