Jump to content

Leaderboard


Popular Content

Showing content with the highest reputation on 04/16/23 in all areas

  1. PeterBelow

    Print a jpeg from a table blob field?

    I found some really ancient code for this in my old snippets file, perhaps you can get it to work. It loads a JPEG from file but you can load it from a TBlobstream attached to your field as well. Printing a JPEG image: uses jpeg, printers; // This procedure has been adapted from the one found near the end of // the Delphi 1 MANUALS.TXT file. procedure PrintBitmap(Bitmap: TBitmap; printrect: TRect); var Info: PBitmapInfo; InfoSize: Cardinal; Image: Pointer; ImageSize: Cardinal; begin with Bitmap do begin GetDIBSizes(Handle, InfoSize, ImageSize); Info := AllocMem(InfoSize); try Image := AllocMem(ImageSize); try GetDIB(Handle, Palette, Info^, Image^); with Info^.bmiHeader, printrect do StretchDIBits(Printer.Canvas.Handle, Left, Top, Right-Left, Bottom-Top, 0, 0, biWidth, biHeight, Image, Info^, DIB_RGB_COLORS, SRCCOPY); finally FreeMem(Image, ImageSize); end; finally FreeMem(Info, InfoSize); end; end; end; procedure TForm1.Button1Click(Sender: TObject); var bmp: TBitmap; jpegimage: TJPegImage; outputrect: TRect; i: Integer; begin jpegimage:= TJPegImage.Create; try jpegimage.Loadfromfile('d:\daten\pix\fraktal_1.jpg'); bmp := tbitmap.Create; try bmp.assign( jpegimage ); i:= 1; While ((i+1)*bmp.Width < printer.pagewidth) and ((i+1)*bmp.Height < printer.pageheight) Do Inc(i); outputrect := Rect( 0, 0, i*bmp.width, i*bmp.height ); try printer.Orientation := poLandscape; printer.begindoc; PrintBitmap( bmp, outputrect ); except printer.abort; raise; end; printer.enddoc; finally bmp.Free; end; finally jpegimage.free end; end;
×