xinyiman:
Ciao ragazzi, devo fare una piccola applicazione web (in futuro sarà una cgi, ora per test è in server embedded) che mi manipola delle immagini. Sembra funzionare tutto, ma non la scrittura sull'immagine. Qualche anima pia con maggior esperienza di me nel settore grafica saprebbe dirmi dove sbaglio? A questo indirizzo trovate da scaricare il test che replica l'errore.
Mimmo:
Ciao, non so darti una risposta certa ma potresti guardare qui https://wiki.lazarus.freepascal.org/fcl-image. Forse devi creare espressamente il font.
Stilgar:
Mumble
Usi il canvas per produrre il testo? https://wiki.freepascal.org/fcl-image
procedure TestFPImgFont; var Img: TFPMemoryImage; Writer: TFPWriterPNG; ms: TMemoryStream; ImgCanvas: TFPImageCanvas; fs: TFileStream; AFont: TFreeTypeFont; begin Img:=nil; ImgCanvas:=nil; Writer:=nil; ms:=nil; fs:=nil; AFont:=nil; try // initialize free type font manager ftfont.InitEngine; FontMgr.SearchPath:='/usr/share/fonts/truetype/ttf-dejavu/'; AFont:=TFreeTypeFont.Create;
// create an image of width 200, height 100 Img:=TFPMemoryImage.Create(200,100); Img.UsePalette:=false; // create the canvas with the drawing operations ImgCanvas:=TFPImageCanvas.create(Img);
// paint white background ImgCanvas.Brush.FPColor:=colWhite; ImgCanvas.Brush.Style:=bsSolid; ImgCanvas.Rectangle(0,0,Img.Width,Img.Height);
// paint text ImgCanvas.Font:=AFont; ImgCanvas.Font.Name:='DejaVuSans'; ImgCanvas.Font.Size:=20; ImgCanvas.TextOut(10,30,'Test');
// write image as png to memory stream Writer:=TFPWriterPNG.create; ms:=TMemoryStream.Create; writer.ImageWrite(ms,Img); // write memory stream to file ms.Position:=0; fs:=TFileStream.Create('testfont.png',fmCreate); fs.CopyFrom(ms,ms.Size); finally AFont.Free; ms.Free; Writer.Free; ImgCanvas.Free; Img.Free; fs.Free; end; end;
begin TestFPImgFont; end. --- Termina codice ---
xinyiman:
Grazie mille alla fine mi avete dato sia la soluzione qui che sul forum internazionale.