1

TWebBrowserコンポーネント内にロードされるサイトのさまざまな領域のスクリーンショットを作成するプログラムを作成しようとしています。

これまでのところ、「ページ全体のスクリーンショットを作成する方法」の解決策しか見つかりませんでしたが、特定の領域をキャプチャすることはできませんでした。ページをどの方向にも引き伸ばすだけです。

http://www.delphifaq.com/faq/f408.shtml

上記のサイトで提示されたコードを使用しています。

コードを変更して、必要なことを実行する方法はありますか? やってみましたが失敗しました。

誰かが少なくともこれを解決する方法を教えてくれれば幸いです。

ありがとう

4

3 に答える 3

4

IHTMLElementRender代わりに、HTMLElemwntのインターフェースを使用することをお勧めします。カーソルの下の要素を簡単に見つけて、これをビットマップにレンダリングできます。

私のTWebBrowserデスカントで​​は、次のように実装しました。

function TWebBrowserIBMA.ElementAsBitmap(pElement : IHTMLElement2) : TBitmap;
var
  pRender       : IHTMLElementRender;
  oBmpPart      : TBitmap;
  nClientWidth  : Integer;
  nClientHeight : Integer;
  nX            : Integer;
  nLastX        : Integer;
  bDoneX        : Boolean;
  nY            : Integer;
  nLastY        : Integer;
  bDoneY        : Boolean;
begin
  Result := TBitmap.Create;

  try
    Result.Height := pElement.scrollHeight;
    Result.Width  := pElement.scrollWidth;
  except
    exit;
  end;

  LockWindowUpdate(Handle);

  if (pElement.QueryInterface(IID_IHTMLElementRender, pRender) = S_OK) then begin
    try
      oBmpPart        := TBitmap.Create;
      oBmpPart.Width  := pElement.scrollWidth;
      oBmpPart.Height := pElement.scrollHeight;
      nClientWidth    := pElement.clientWidth;
      nClientHeight   := pElement.clientHeight;

      try
        nX      := pElement.scrollWidth; 
        nLastX  := -1;
        bDoneX  := false;

        while not bDoneX do begin
          pElement.scrollLeft := nX;
          nX := pElement.scrollLeft;
          if nLastX = -1 then begin
            nLastX := nX + nClientWidth;
          end;
          nY     := pElement.scrollHeight;
          nLastY := (-1);
          bDoneY := false;

          while not bDoneY do begin
            pElement.scrollTop := nY;
            nY := pElement.scrollTop;

            if nLastY = -1 then begin
              nLastY := nY + nClientHeight;
            end;

            if (pRender.DrawToDC(oBmpPart.Canvas.Handle) = S_OK) then begin
              BitBlt(Result.Canvas.Handle, nX, nY, nLastX-nX, nLastY-nY, oBmpPart.Canvas.Handle, 2, 2,SRCCOPY);
            end;

            bDoneY  := (nY = 0);
            nLastY  := nY;
            Dec(nY, nClientHeight-4);  
          end;

          bDoneX  := (nX = 0);
          nLastX  := nX;
          Dec(nX, (nClientWidth-4));
        end;
      finally
        FreeAndNil(oBmpPart);
      end;
    finally
      pRender := nil;
    end;
  end;

  LockWindowUpdate(0);
end;
于 2011-03-24T08:05:16.880 に答える
1

sourceBitmap.Canvas.CopyRectを使用できます

于 2011-03-23T13:05:04.290 に答える
0

sourceDrawRect必要な領域がこのビットマップに収まるように、ビューオブジェクトを描画するビットマップの幅と高さを超えて、上と左が負で、右と下が負の長方形に設定しようとしましたか?

于 2011-03-23T13:00:12.930 に答える