Delphi Programming Forum
C++Builder  |  Delphi  |  FireMonkey  |  C/C++  |  Free Pascal  |  Firebird
볼랜드포럼 BorlandForum
 경고! 게시물 작성자의 사전 허락없는 메일주소 추출행위 절대 금지
델파이 포럼
Q & A
FAQ
팁&트릭
강좌/문서
자료실
컴포넌트/라이브러리
FreePascal/Lazarus
볼랜드포럼 홈
헤드라인 뉴스
IT 뉴스
공지사항
자유게시판
해피 브레이크
공동 프로젝트
구인/구직
회원 장터
건의사항
운영진 게시판
회원 메뉴
북마크
델마당
볼랜드포럼 광고 모집

델파이 팁&트릭
Delphi Programming Tip&Tricks
[233] [VCL] GetPanelImage
장성호 [nasilso] 13022 읽음    2008-03-07 10:27
GetFormImage라는 함수를 아십니까?

아래팁에서 이함수를 이용했었는데요..
http://cbuilder.borlandforum.com/impboard/impboard.dll?action=read&db=bcb_tip&no=742

GetFormImage이미지는 Form의 Client영역에 모든 화면을 캡쳐해줍니다.
다른 window컨트롤이 올라와 있더라도 모두다....


그런데 Client영역 전체가 아닌 일부 영역만을 캡쳐하고싶을때는 어떻게 하면 될까요?
할 수 있습니다.  GetFormImage로 캡쳐해서 해당 영역만 짤라내면 되니까요

그런데 해당 컨트롤들의 일부가 다른 Control에 가려져 있다면 가능할가요?
문론 가능한 방법은 있습니다만 ..

아래 GetPanelImage 함수를 이용하면 편리합니다.

이함수는 문론 GetFormImage 처럼
Panel뿐만 아니라 그위에 올라와 있는 모든 Control의 이미지를 캡쳐해서
TBitmap *로 반환해 줍니다.

//C++Builder
Graphics::TBitmap * __fastcall GetPanelImage(TPanel *Panel)
{
    if(Panel==NULL)return NULL;

    Graphics::TBitmap *bmp=NULL;

    bmp=new Graphics::TBitmap;
    bmp->Width=Panel->ClientWidth;
    bmp->Height=Panel->ClientHeight;
    bmp->Canvas->Brush = Panel->Brush;
    bmp->Canvas->FillRect(Panel->ClientRect);
    bmp->Canvas->Lock();

    try
    {
        int Ofs=0;
        if(GetWindowLong(Panel->Handle, GWL_STYLE) & WS_BORDER )
            Ofs = -1;  // Don't draw form border
        else
            Ofs = 0;  // There is no border

        Panel->PaintTo(bmp->Canvas->Handle, Ofs, Ofs);

    }
    __finally
    {
        bmp->Canvas->Unlock();
    }

    return bmp;
}


//Delphi
function GetPanelImage(Panel:TPanel): TBitmap;
var
  Ofs: Integer;
begin
  if Assigned(Panel) then
  begin
      Result := TBitmap.Create;
      try
        Result.Width := Panel.ClientWidth;
        Result.Height := Panel.ClientHeight;
        Result.Canvas.Brush := Panel.Brush;
        Result.Canvas.FillRect(Panel.ClientRect);
        Result.Canvas.Lock;
        try
          if GetWindowLong(Panel.Handle, GWL_STYLE) and WS_BORDER <> 0 then
            Ofs := -1  // Don't draw form border
          else
            Ofs := 0;  // There is no border
          Panel.PaintTo(Result.Canvas.Handle, Ofs, Ofs);
        finally
          Result.Canvas.Unlock;
        end;
      except
        Result.Free;
        raise;
      end;
  end;
end;


ㅋㅋ
근데 위함수 어떻게 만들었을까요?
간단합니다. VCL에 있는 GetFormImage의 소스를 보고 거의 그대로 copy한것입니다.
TPanel말고 다른 Window컨트롤에도 얼마든지 응용가능할것입니다.

단. WebBroswer라던가 다른 OLE오브젝트가 올라와있는경우
해당화면은 캡쳐안됩니다.
GetFormImage도 마찬가지구요...


참고
//VCL의 GetFormImage 소스입니다.

function TCustomForm.GetFormImage: TBitmap;
var
  Ofs: Integer;
begin
  Result := TBitmap.Create;
  try
    Result.Width := ClientWidth;
    Result.Height := ClientHeight;
    Result.Canvas.Brush := Brush;
    Result.Canvas.FillRect(ClientRect);
    Result.Canvas.Lock;
    try
      if GetWindowLong(Handle, GWL_STYLE) and WS_BORDER <> 0 then
        Ofs := -1  // Don't draw form border
      else
        Ofs := 0;  // There is no border
      PaintTo(Result.Canvas.Handle, Ofs, Ofs);
    finally
      Result.Canvas.Unlock;
    end;
  except
    Result.Free;
    raise;
  end;
end;



그럼..

+ -

관련 글 리스트
233 [VCL] GetPanelImage 장성호 13022 2008/03/07
(링크)     C++Builder Tip'N Tricks > [VCL] GetPanelImage
Google
Copyright © 1999-2015, borlandforum.com. All right reserved.