Mega Code Archive

 
Categories / Delphi / Printing
 

Timage yazicidan nasil yazdirilir

// Printers unit'ini eklemeyi unutmayin. procedure TForm1.PrintBitmap(TheImage : TImage); var SourceRect, PrintRect: TRect; Info: PBitmapInfo; InfoSize: dword; Image: Pointer; ImageSize: dword; Bits: HBitmap; DIBWidth, DIBHeight: LongInt; PrintWidth, PrintHeight: LongInt; PrintBitmap: TBitmap; begin Printer.BeginDoc; PrintBitmap := TBitmap.Create; SourceRect.Left := TheImage.Left; SourceRect.Top := TheImage.Top; SourceRect.Right := TheImage.Left + Image1.Width; SourceRect.Bottom := TheImage.Top + Image1.Height; { Set up the height and width of the destination bitmap } PrintBitmap.Height := SourceRect.Bottom - SourceRect.Top + 1; PrintBitmap.Width := SourceRect.Right - SourceRect.Left + 1; { Set the destination coordinates } PrintRect.Top := 0; PrintRect.Left := 0; PrintRect.Right := PrintBitmap.Width; PrintRect.Bottom := PrintBitmap.Height; { Copy from the screen to the printer } PrintBitmap.Canvas.CopyRect(PrintRect, self.Canvas, SourceRect); { Here we will stretch the bitmap, and do the printing } with Printer, Canvas do begin { Get the handle to the Print bitmap } Bits := PrintBitmap.Handle; { Get the information from the bitmap } GetDIBSizes(Bits, InfoSize, ImageSize); { Allocate the required memory for the operation } GetMem(Info, InfoSize); try GetMem(Image, ImageSize); try GetDIB(Bits, 0, Info^, Image^); with Info^.bmiHeader do begin DIBWidth := biWidth; DIBHeight := biHeight; end; { Adjust the print sizes (expand or contract) } PrintWidth := MulDiv(DIBWidth, GetDeviceCaps(Handle, LOGPIXELSX), PixelsPerInch); PrintHeight := MulDiv(DIBHeight, GetDeviceCaps(Handle, LOGPIXELSY), PixelsPerInch); { Move from one canvas to the other while stretching or compressing the image } StretchDIBits(Canvas.Handle, 0, 0, PrintWidth, PrintHeight, 0, 0,DIBWidth, DIBHeight, Image, Info^, DIB_RGB_COLORS, SRCCOPY); finally FreeMem(Image, ImageSize); end; finally FreeMem(Info, InfoSize); end; end; Printer.EndDoc; end;