Delphi-PRAXiS

Delphi-PRAXiS (https://www.delphipraxis.net/forum.php)
-   Win32/Win64 API (native code) (https://www.delphipraxis.net/17-win32-win64-api-native-code/)
-   -   Image from TWebBrowser -> TPicture (https://www.delphipraxis.net/171671-image-twebbrowser-tpicture.html)

Ryzinski 18. Nov 2012 20:56

Image from TWebBrowser -> TPicture
 
hi!

i found a c# solution but i have no idea how to do this in delphi.

Code:
  IHTMLDocument2 doc = (IHTMLDocument2)wb1.Document.DomDocument;
            IHTMLControlRange imgRange = (IHTMLControlRange)((HTMLBody)doc.body).createControlRange();

            foreach (IHTMLImgElement img in doc.images)
            {
                if (img.nameProp.Contains('sometag'))
                {
                    IHTMLElementRenderFixed render = (IHTMLElementRenderFixed)img;
                    Bitmap bmp = new Bitmap(img.width, img.height);
                    Graphics g = Graphics.FromImage(bmp);
                    IntPtr hdc = g.GetHdc();
                    render.DrawToDC(hdc);
                    g.ReleaseHdc(hdc);

                    ImageBmp = bmp;
                    break;
                }
            }
        }

Sir Rufo 18. Nov 2012 21:59

AW: Image from TWebBrowser -> TPicture
 
It is nearly exact the same in delphi
Delphi-Quellcode:
var
  doc :     IHTMLDocument2;
  imgRange : IHTMLControlRange;
  img :     IHTMLImgElement;
  render :  IHTMLElementRender;

  bmp : TBitmap;
  _hdc : HDC;

  img_NameProp : string;
  img_idx :     Integer;
begin
  doc     := Browser_WebBrowser.Document as IHTMLDocument2;
  imgRange := ( doc.body as HTMLBody ).createControlRange as IHTMLControlRange;

  for img_idx := 0 to Pred( doc.images.length ) do
    begin

      img := doc.images.item( img_idx, EmptyParam ) as IHTMLImgElement;

      img_NameProp := Utf8ToAnsi( UTF8Encode( img.nameProp ) );
      if ContainsText( img_NameProp, 'sometag' )
      then
        begin
          render := ( img as IHTMLElementRender );

          bmp := TBitmap.Create;
          try
            bmp.Width := img.Width;
            bmp.Height := img.Height;

            _hdc := bmp.Canvas.Handle;

            render.DrawToDC( _hdc );

            Image1.Picture.Assign( bmp );

          finally
            bmp.Free;
          end;
          break;
        end;
    end;
end;

Ryzinski 18. Nov 2012 22:22

AW: Image from TWebBrowser -> TPicture
 
// Whoops :)

Sir Rufo 18. Nov 2012 22:26

AW: Image from TWebBrowser -> TPicture
 
Yes Mr. Joey Smith

Bummi 18. Nov 2012 22:57

AW: Image from TWebBrowser -> TPicture
 
für alle die den jetzt nicht verstanden haben:
http://stackoverflow.com/questions/1...er-to-tpicture


Alle Zeitangaben in WEZ +1. Es ist jetzt 12:49 Uhr.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
LinkBacks Enabled by vBSEO © 2011, Crawlability, Inc.
Delphi-PRAXiS (c) 2002 - 2023 by Daniel R. Wolf, 2024 by Thomas Breitkreuz