Printing in a CGI Application lazarus / 39-Graphics ---------------------------------------------------------------------- franchus3 · 2010-09-13 11:21 Hi All,   I'm trying to print a image. But I get the following error: "Failed to get raw image description from bitmap". My code is: Code: [Select]var   myBit, PrintBit: TFPMemoryImage;   PrintBitCanvas: TFPImageCanvas;   FinalCanvas: TFPImageCanvas;   myBitCanvas: TFPImageCanvas;   writer: TFPWriterBMP;   imageBMP: TBitmap;   imageToPrint: TMemoryStream;   ltop, lleft: integer;   dR, sR: TRect;   dtl, dtr, dbl, dbr: TPoint; begin   Printer.SetPrinter(printerName);   //get a resized copy of the bitmap :   myBit := resizeBitmap(printerName, B);   //create page bitmap   PrintBit := TFPMemoryImage.Create(0,0);   PrintBit.UsePalette:= False;   PrintBit.Width := getPrinterPageWidth(printerName);   PrintBit.Height := getPrinterPageHeight(printerName);  // PrintBit.Canvas.Brush.Color := clwhite;   //PrintBit.Canvas.Brush.Style := bssolid;     PrintBitCanvas:=TFPImageCanvas.create(PrintBit);   //find out where to place the bitmap to be printed in the center of our page:   lleft := (getPrinterPageWidth(printerName) - myBit.Width) div 2;   ltop := (getPrinterPageHeight(printerName) - myBit.Height) div 2;   //copying and positioning bitmap on page bitmap   sR := Rect(0, 0, myBit.Width, myBit.Height);   dR := Rect(lleft, ltop, lleft + myBit.Width, ltop + myBit.Height);   //PrintBit.canvas.CopyRect(dR, myBit.Canvas, sR);   myBitCanvas:=TFPImageCanvas.create(myBit);   PrintBitCanvas.CopyRect(lleft, ltop, myBitCanvas, sR);   //printing outline   dtl.x := dr.Left;   dtl.y := dr.Top;   dtr.x := dr.Right;   dtr.y := dr.Top;   dbr.x := dr.Right;   dbr.y := dr.Bottom;   dbl.x := dr.Left;   dbl.y := dr.Bottom;   with Printer do   begin     if not (Printer.PrinterState = psReady) then       raise Exception.Create('La impresora no está lista');     Printer.BeginDoc;     Printer.Title:=job_name;     Printer.NewPage;     writer:= TFPWriterBMP.Create;     imageToPrint:=TMemoryStream.Create;         PrintBit.SaveToStream(imageToPrint, writer);     imageToPrint.Position := 0;     imageBMP:= TBitmap.Create;     imageBMP.LoadFromStream(imageToPrint);            Printer.Canvas.TextOut(10, 10, 'Hola');      Printer.Canvas.StretchDraw(Rect(0, 0, Printer.PageWidth, Printer.PageHeight),imageBMP);      Printer.Canvas.Draw(0,0, imageBMP);     Printer.EndDoc;   end;   imageToPrint.Free;   myBitCanvas.Free;   PrintBit.Free;    I didn't get any printing using the Printer.Canvas.Textout,StrechDraw or Draw. I've added Printer4Lazarus package. I coudn't find what I'm doing wrong.  I'll apreciate any guidance! Franco ---------------------------------------------------------------------- franchus3 · 2010-09-13 14:56 I correct myself, I was using a CUPS-PDF printer and for some reason don't print Printer.Canvas,Textout. But in a physical printer it works without problems. However if I try print images, I still getting the error above. Franco ---------------------------------------------------------------------- mas steindorff · 2010-09-13 18:54 Printer.Canvas.TextOut(10, 10, 'Hola');      Printer.Canvas.StretchDraw(Rect(0, 0, Printer.PageWidth, Printer.PageHeight),imageBMP);      Printer.Canvas.Draw(0,0, imageBMP); I use this same code with my pdf printer but without the .Draw code. my code is simply: Code: [Select]    printer.BeginDoc;     Printer.Canvas.StretchDraw(r, Mybitmap); //Bitmap.Canvas.Handle;     Printer.EndDoc; I had errors with the draw command as well so i removed it. ---------------------------------------------------------------------- franchus3 · 2010-09-14 11:30 Hi mas steindorff,   Do you use "NoGui" fpc option compiler on your test project? I think that the problem is that I shouldn't use TBipmap, because it's a graphic component. This code works fine if I compile this like a GUI Application. I have the "Failed to get raw image description from bitmap" error, and below it says "TRasterImage.BitmapHandleNeeded: Unable to create handles, using default". I mean, I did some changes to, for example, get width and height of jpg images because when I used graphics components, these don't work. Instead of Graphics, I use fc-image. I'm using Laz 0.9.29 and fpc 2.5.1 ---------------------------------------------------------------------- mas steindorff · 2010-09-14 16:17 Quote from: franchus3 on September 14, 2010, 01:30:59 pmHi mas steindorff,   Do you use "NoGui" fpc option compiler on your test project? I think that the problem is that I shouldn't use TBipmap, because it's a graphic component. This code works fine if I compile this like a GUI Application. I used the code in GUI.  I just saw the draw command and remembered my woes with it.  You may look at the inheradance of a tbitmap.  It has some relations with the FCxxxx that you may be able to do some casting with. ---------------------------------------------------------------------- martinrame · 2018-05-21 12:20 I'm having exactly the same problem, did you find a way to print bitmaps from CGI?