Utilisateur anonyme
-
5 avril 2007 à 12:48
Utilisateur anonyme -
9 avril 2007 à 18:04
Salut à tous,
Je travaille actuellement avec le composant TGraphXY de Kénavo. J'ai besoin de pouvoir l'imprimer en noir et blanc, j'utilise donc ce code là :
procedure TForm1.Print_BtClick(Sender: TObject);
Var
Img:TImage;
BitMap:TBitMap;
BcCl,GdCl,Cl:TColor;
Rect:TRect;
begin
If not PrinterSetupDialog1.Execute then Exit;
BitMap:=TBitMap.Create;
BitMap.Width:=Graph.Width;
BitMap.Height:=graph.Height;
With Graph Do
Begin
BcCl:=BackColor;
GdCl:=GridColor;
Cl:=Color;
BackColor:=ClWhite;
GridColor:=ClBlack;
Color:=ClBlack;
Graph.PaintTo(BitMap.Canvas,0,0);
BackColor:=BcCl;
GridColor:=GdCl;
Color:=Cl;
End;
try
With Printer Do
Begin
Rect.Left:=(Width-BitMap.Width) Div 2;
Rect.Right:=Rect.Left+BitMap.Width;
Rect.Top:=(height-BitMap.height) Div 2;
Rect.Bottom:=Rect.Top+BitMap.Height;
Img:=TImage.Create(nil);
Img.Picture.Bitmap.Assign(BitMap);
While Img.Picture.Bitmap.Empty Do
Application.ProcessMessages;
BeginDoc;
Canvas.StretchDraw(Rect,Img.Picture.Bitmap);
EndDoc;
Img.Free;
End;
Except
Showmessage('Imprimante absnete ou autre erreur');
End;
BitMap.Free;
End;
Malheureusement j'obtient une magnifique page blanche : Si quelqu'un a une idée du pourquoi du comment ?
ThWilliam
Messages postés418Date d'inscriptionmardi 3 janvier 2006StatutMembreDernière intervention26 novembre 20134 7 avril 2007 à 19:24
Salut Francky,
Je ne connais pas TGraphXY, mais je vois plusieurs problèmes dans ton code :
1) dans with printer do... , tu utilises Width et Height : à remplacer par PageWidth et PageHeight.
2) ton code ne s'adapte pas à un bitmap plus grand que le nbpixels de la page (mais ce n'est peut-être pas nécessaire ?).
3) pourquoi créer un TImage, alors qu'il suffit de faire : Printer.Canvas.StretchDraw(Rect, Bitmap); ?
ThWilliam
Messages postés418Date d'inscriptionmardi 3 janvier 2006StatutMembreDernière intervention26 novembre 20134 9 avril 2007 à 10:40
Salut Francky.
Comme tu dessines sur le Canvas du Bitmap, j'ai fait le test suivant :
procedure TForm1.Button1Click(Sender: TObject);
var
Bitmap: TBitmap;
begin
Bitmap:= TBitmap.Create;
with Bitmap do
begin
Width:= 300;
Height:= 300;
//
Canvas.Brush.Color:= clBlack;
Canvas.FillRect(Rect(0,0,Width,Height));
end;
with Printer do
begin
BeginDoc;
Canvas.Draw(300,300,Bitmap);
EndDoc;
end;
Bitmap.Free;
end;
Résultat : page blanche !!!
Si à l'endroit des //, tu codes : PixelFormat:= pf24Bit; (ou pf32bit) ... tout marche bien.
Je suppose que l'explication est qu'une imprimante travaille en mode RGB et qu'il faut donc transformer le bitmap en niveaux de couleurs RGB.
@Kénavo : comme quoi il est pas démodé ton composant .
@Thierry : Pour PageWidth et PageHeight : problème de copier coller autant pour moi .(toute facon, Printer.width n'existe pas il me semble).
Pourquoi utiliser un TImage plutot qu'un TBitMap : ben comme ca ne fonctionnait pas j'ai essayé de bidouiller.
En fait que cela soit un TImage ou TBitmap, la partie qui plante est la partie impression : si on "remplace" Printer.Canvas.StretchDraw(Rect, Bitmap) par clipboard.Assign(Image1.BitMap) ou clipboard.Assign(Image1.Img.Picture) cela fonctionne nickel : avec un coller on récupère bien l'image centrée comme il faut. Je pense qu'il y a un problème de refresh quelque part mais je ne vois pas ou et surtout pas pourquoi.
Je sais que l'impression des bitmap est délicate mais à ce point, je me doutais pas.
Merci à vous
Vous n’avez pas trouvé la réponse que vous recherchez ?