Delphi: QuickReport Marca d’agua

1

Posted on : 19-07-2009 | By : Paulo H Oliveira | In : Delphi
Esta dica nos mostra como colocar uma imagem de fundo na página, simulando o efeito marca d’água. Para tal, declaremos a procedure:
procedure ImprimeBitMap(Cnv: TCanvas; BitMap: TBitMap; R: TRect);
var
Info : PBitMapInfo;
InfoSize : DWORD;
Image : Pointer;
ImageSize : DWORD;
begin
with BitMap do
begin
GetDIBSizes(Handle, InfoSize, ImageSize);
GetMem(Info, InfoSize);
try
Getmem(Image, ImageSize);
try
GetDIB(Handle, Palette, Info^,Image^);
with Info^.bmiHeader do
StretchDIBits(Cnv.Handle, R.Left, R.Top,
R.Right – R.Left, R.Bottom – R.Top,
0, 0, biWidth, biHeight, Image,
Info^, DIB_RGB_COLORS, SRCAND);
finally
FreeMem(Image, ImageSize);
end;
finally
FreeMem(Info, InfoSize);
end;
end;
end;
Antes de usá-la, crie/copie uma imagem de tonalidade clara para a unidade C:, e no evento AfterPrint da última banda existente no seu relatório (normalmente PageFooter), faça:
procedure TForm1.PageFooterBand1AfterPrint(Sender: TQRCustomBand;
BandPrinted: Boolean);
const
Imagem = ‘c:\figura.bmp’;
//altere aqui o nome/caminho da sua imagem
var
BitMap : TBitMap;
R      : TRect;
X, Y   : integer;
begin
BitMap := TBitMap.Create;
try
if not FileExists(Imagem) then
begin
messagebox(handle,
‘O arquivo de imagem não existe ou foi removido !’,
‘Atenção’, MB_OK or MB_ICONWARNING);
SetActiveWindow(Application.Handle);
end
else
begin
BitMap.LoadFromFile(Imagem);
with QuickRep1.QRPrinter do
begin
Y := YPos(PaperLengthValue) div 6;
X := XPos(PaperWidthValue) div 4;
R := Rect(X, 2 * Y, 3 * X, 4 * Y);
ImprimeBitMap(Canvas, BitMap, R);
end;
end;
finally
BitMap.Free;
end;
end;
Agora é só rodar e testar! ;-)
Só lembrando que, como qualquer outro código nos eventos Befor e AfterPrint, não funciona em Design Time.

Esta dica nos mostra como colocar uma imagem de fundo na página, simulando o efeito marca d’água. Para tal, declaremos a procedure:

procedure ImprimeBitMap(Cnv: TCanvas; BitMap: TBitMap; R: TRect);

var

Info : PBitMapInfo;

InfoSize : DWORD;

Image : Pointer;

ImageSize : DWORD;

begin

with BitMap do

begin

GetDIBSizes(Handle, InfoSize, ImageSize);

GetMem(Info, InfoSize);

try

Getmem(Image, ImageSize);

try

GetDIB(Handle, Palette, Info^,Image^);

with Info^.bmiHeader do

StretchDIBits(Cnv.Handle, R.Left, R.Top,

R.Right – R.Left, R.Bottom – R.Top,

0, 0, biWidth, biHeight, Image,

Info^, DIB_RGB_COLORS, SRCAND);

finally

FreeMem(Image, ImageSize);

end;

finally

FreeMem(Info, InfoSize);

end;

end;

end;

Antes de usá-la, crie/copie uma imagem de tonalidade clara para a unidade C:, e no evento AfterPrint da última banda existente no seu relatório (normalmente PageFooter), faça:

procedure TForm1.PageFooterBand1AfterPrint(Sender: TQRCustomBand;

BandPrinted: Boolean);

const

Imagem = ‘c:\figura.bmp’;

//altere aqui o nome/caminho da sua imagem

var

BitMap : TBitMap;

R      : TRect;

X, Y   : integer;

begin

BitMap := TBitMap.Create;

try

if not FileExists(Imagem) then

begin

messagebox(handle,

‘O arquivo de imagem não existe ou foi removido !’,

‘Atenção’, MB_OK or MB_ICONWARNING);

SetActiveWindow(Application.Handle);

end

else

begin

BitMap.LoadFromFile(Imagem);

with QuickRep1.QRPrinter do

begin

Y := YPos(PaperLengthValue) div 6;

X := XPos(PaperWidthValue) div 4;

R := Rect(X, 2 * Y, 3 * X, 4 * Y);

ImprimeBitMap(Canvas, BitMap, R);

end;

end;

finally

BitMap.Free;

end;

end;

Agora é só rodar e testar! ;-)

Só lembrando que, como qualquer outro código nos eventos Befor e AfterPrint, não funciona em Design Time.

Compartilhe :

  • Stumble upon
  • twitter

Comentários (1)

Muito bom!
Ajudou muito!
Valeu!

Escreva um comentário