Como Imprimir o Canvas de um TImage ???
Caros Amigos
:lol: Consigo montar um gráfico desenhando linhas, caixas, setas em um TImage.
:cry: Não consigo imprimi-lo. A propriedade Picture do TImage vem com uma figura em branco. Copiar o Canvas do TImage para o Canvas da Impressora também não dá em nada.
Utizando os Metodos Draw ou StretchDraw no Canvas da Impressora também não resultam em nada. Já tentei utilizar até impressão em alta qualidade, mas nada. :?
Alguem tem alguma fórmula :?:
:? Marconi
:lol: Consigo montar um gráfico desenhando linhas, caixas, setas em um TImage.
:cry: Não consigo imprimi-lo. A propriedade Picture do TImage vem com uma figura em branco. Copiar o Canvas do TImage para o Canvas da Impressora também não dá em nada.
Utizando os Metodos Draw ou StretchDraw no Canvas da Impressora também não resultam em nada. Já tentei utilizar até impressão em alta qualidade, mas nada. :?
Alguem tem alguma fórmula :?:
:? Marconi

Marconi
Curtidas 0
Melhor post

Marconi
22/09/2003
Caro [b:dc5c011e08]cebikyn[/b:dc5c011e08]
O segundo exemplo da primeira dica funcionou perfeitamente, por isto estou transcrevendo abaixo para que outros aproveitem quando estiverem pesquisando.
// from www.experts-exchange.com
uses
printers;
procedure DrawImage(Canvas: TCanvas; DestRect: TRect; ABitmap: TBitmap);
var
Header, Bits: Pointer;
HeaderSize: DWORD;
BitsSize: DWORD;
begin
GetDIBSizes(ABitmap.Handle, HeaderSize, BitsSize);
Header := AllocMem(HeaderSize);
Bits := AllocMem(BitsSize);
try
GetDIB(ABitmap.Handle, ABitmap.Palette, Header^, Bits^);
StretchDIBits(Canvas.Handle, DestRect.Left, DestRect.Top,
DestRect.Right, DestRect.Bottom,
0, 0, ABitmap.Width, ABitmap.Height, Bits, TBitmapInfo(Header^),
DIB_RGB_COLORS, SRCCOPY);
finally
FreeMem(Header, HeaderSize);
FreeMem(Bits, BitsSize);
end;
end;
procedure PrintImage(Image: TImage; ZoomPercent: Integer);
// if ZoomPercent=100, Image will be printed across the whole page
var
relHeight, relWidth: integer;
begin
Screen.Cursor := crHourglass;
Printer.BeginDoc;
with Image.Picture.Bitmap do
begin
if ((Width / Height) > (Printer.PageWidth / Printer.PageHeight)) then
begin
// Stretch Bitmap to width of PrinterPage
relWidth := Printer.PageWidth;
relHeight := MulDiv(Height, Printer.PageWidth, Width);
end
else
begin
// Stretch Bitmap to height of PrinterPage
relWidth := MulDiv(Width, Printer.PageHeight, Height);
relHeight := Printer.PageHeight;
end;
relWidth := Round(relWidth * ZoomPercent / 100);
relHeight := Round(relHeight * ZoomPercent / 100);
DrawImage(Printer.Canvas, Rect(0, 0, relWidth, relHeight), Image.Picture.Bitmap);
end;
Printer.EndDoc;
Screen.cursor := crDefault;
end;
// Example Call:
procedure TForm1.Button1Click(Sender: TObject);
begin
// Print image at 40¬ zoom:
PrintImage(Image1, 40);
end;
Marconi
O segundo exemplo da primeira dica funcionou perfeitamente, por isto estou transcrevendo abaixo para que outros aproveitem quando estiverem pesquisando.
// from www.experts-exchange.com
uses
printers;
procedure DrawImage(Canvas: TCanvas; DestRect: TRect; ABitmap: TBitmap);
var
Header, Bits: Pointer;
HeaderSize: DWORD;
BitsSize: DWORD;
begin
GetDIBSizes(ABitmap.Handle, HeaderSize, BitsSize);
Header := AllocMem(HeaderSize);
Bits := AllocMem(BitsSize);
try
GetDIB(ABitmap.Handle, ABitmap.Palette, Header^, Bits^);
StretchDIBits(Canvas.Handle, DestRect.Left, DestRect.Top,
DestRect.Right, DestRect.Bottom,
0, 0, ABitmap.Width, ABitmap.Height, Bits, TBitmapInfo(Header^),
DIB_RGB_COLORS, SRCCOPY);
finally
FreeMem(Header, HeaderSize);
FreeMem(Bits, BitsSize);
end;
end;
procedure PrintImage(Image: TImage; ZoomPercent: Integer);
// if ZoomPercent=100, Image will be printed across the whole page
var
relHeight, relWidth: integer;
begin
Screen.Cursor := crHourglass;
Printer.BeginDoc;
with Image.Picture.Bitmap do
begin
if ((Width / Height) > (Printer.PageWidth / Printer.PageHeight)) then
begin
// Stretch Bitmap to width of PrinterPage
relWidth := Printer.PageWidth;
relHeight := MulDiv(Height, Printer.PageWidth, Width);
end
else
begin
// Stretch Bitmap to height of PrinterPage
relWidth := MulDiv(Width, Printer.PageHeight, Height);
relHeight := Printer.PageHeight;
end;
relWidth := Round(relWidth * ZoomPercent / 100);
relHeight := Round(relHeight * ZoomPercent / 100);
DrawImage(Printer.Canvas, Rect(0, 0, relWidth, relHeight), Image.Picture.Bitmap);
end;
Printer.EndDoc;
Screen.cursor := crDefault;
end;
// Example Call:
procedure TForm1.Button1Click(Sender: TObject);
begin
// Print image at 40¬ zoom:
PrintImage(Image1, 40);
end;
Marconi
GOSTEI 1
Mais Respostas

Cebikyn
09/09/2003
Tem duas opções em:
http://www.swissdelphicenter.ch/torry/showcode.php?id=744
http://www.swissdelphicenter.ch/torry/showcode.php?id=744
GOSTEI 0

Cebikyn
09/09/2003
Outra opção, esta é da Borland (e mais complicada tb...):
http://community.borland.com/article/0,1410,16211,00.html
Se ainda assim não funcionar, deixe uma msg...
http://community.borland.com/article/0,1410,16211,00.html
Se ainda assim não funcionar, deixe uma msg...
GOSTEI 0

Marconi
09/09/2003
Muito Obrigado pelas dicas.
Vou tentar as soluções indicadas.
Mas acho que vão dar certo.
Marconi
Vou tentar as soluções indicadas.
Mas acho que vão dar certo.
Marconi
GOSTEI 0