begin process at 2010 02 09 23:18:09
  Trouver un code source :
 
dans
 
Accueil > 

Code

 > 

Graphique

 > CANVAS EN MILLIMÈTRE

CANVAS EN MILLIMÈTRE


 Information sur la source

Note :
9 / 10 - par 1 personne
9,00 / 10

  • 1

  • 2

  • 3

  • 4

  • 5

  • 6

  • 7

  • 8

  • 9

  • 10
Catégorie :Graphique Classé sous :canvas, millimètre, printer Niveau :Débutant Date de création :02/02/2008 Date de mise à jour :02/02/2008 19:33:59 Vu / téléchargé :3 458 / 564

Auteur : barbichette

Ecrire un message privé
Site perso
Commentaire sur cette source (16)
Ajouter un commentaire et/ou une note

 Description

Ben voilà, rien de bien révolutionnaire.
C'est une classe dérivé de TCanvas qui prend comme paramètre dans les procédures de dessins des valeurs en 1/10 de millimètre.
Donc TMMCanvas.rectangle(0,0,1000,1000) trace un carré de 10cm de côté.
Pour une utilisation simple, il suffit de transtyper un canvas en tmmcanvas.
Par exemple :
tmmcanvas(form1.canvas).ellypse(0,0,200,200); trace un cercle de 2cm de diamètre sur le canvas d'une fenêtre.

Très pratique pour le canvas de l'objet Printer. Ainsi, on trace en mm sur l'imprimante.

Source

  • unit UMMCanvas;
  • interface
  • uses windows,graphics;
  • type
  • TMMCanvas=class(Tcanvas)
  • private
  • function ConvertX(x:integer):integer;
  • function ConvertY(y:integer):integer;
  • function InvConvertX(x:integer):integer;
  • function InvConvertY(y:integer):integer;
  • function ConvertPoint(pt:TPoint):TPoint;
  • function ConvertRect(rect:trect):TRect;
  • function GetPixel(X, Y: Integer): TColor;
  • procedure SetPixel(X, Y: Integer; Value: TColor);
  • protected
  • public
  • constructor Create;
  • destructor Destroy; override;
  • procedure MMArc(X1, Y1, X2, Y2, X3, Y3, X4, Y4: Integer);
  • procedure MMBrushCopy(Const Dest: TRect; Bitmap: TBitmap; Const Source: TRect; Color: TColor);
  • procedure MMChord(X1, Y1, X2, Y2, X3, Y3, X4, Y4: Integer);
  • procedure MMCopyRect(Const Dest: TRect; Canvas: TCanvas;Const Source: TRect);
  • procedure MMDraw(X, Y: Integer; Graphic: TGraphic);
  • procedure MMDrawFocusRect(const Rect: TRect);
  • procedure MMEllipse(X1, Y1, X2, Y2: Integer); overload;
  • procedure MMEllipse(const Rect: TRect); overload;
  • procedure MMFillRect(const Rect: TRect);
  • procedure MMFloodFill(X, Y: Integer; Color: TColor; FillStyle: TFillStyle);
  • procedure MMFrameRect(const Rect: TRect);
  • procedure MMLineTo(X, Y: Integer);
  • procedure MMMoveTo(X, Y: Integer);
  • procedure MMPie(X1, Y1, X2, Y2, X3, Y3, X4, Y4: Integer);
  • procedure MMPolygon(const Points: array of TPoint);
  • procedure MMPolyline(const Points: array of TPoint);
  • procedure MMPolyBezier(const Points: array of TPoint);
  • procedure MMPolyBezierTo(const Points: array of TPoint);
  • procedure MMRectangle(X1, Y1, X2, Y2: Integer); overload;
  • procedure MMRectangle(const Rect: TRect); overload;
  • procedure MMRoundRect(X1, Y1, X2, Y2, X3, Y3: Integer);
  • procedure MMStretchDraw(const Rect: TRect; Graphic: TGraphic);
  • function MMTextExtent(const Text: string): TSize;
  • function MMTextHeight(const Text: string): Integer;
  • procedure MMTextOut(X, Y: Integer; const Text: string);
  • procedure MMTextRect(Rect: TRect; X, Y: Integer; const Text: string);
  • function MMTextWidth(const Text: string): Integer;
  • property MMPixels[X, Y: Integer]: TColor read GetPixel write SetPixel;
  • published
  • end;
  • implementation
  • function TMMCanvas.ConvertX(x:integer):integer;
  • begin
  • result:=GetDeviceCaps(Handle, LOGPIXELSX);
  • result:=x*result div 254;
  • end;
  • function TMMCanvas.ConvertY(y:integer):integer;
  • begin
  • result:=GetDeviceCaps(Handle, LOGPIXELSY);
  • result:=y*result div 254;
  • end;
  • function TMMCanvas.InvConvertX(x:integer):integer;
  • begin
  • result:=GetDeviceCaps(Handle, LOGPIXELSX);
  • result:=x*254 div result;
  • end;
  • function TMMCanvas.InvConvertY(y:integer):integer;
  • begin
  • result:=GetDeviceCaps(Handle, LOGPIXELSY);
  • result:=y*254 div result;
  • end;
  • function TMMCanvas.ConvertPoint(pt:TPoint):TPoint;
  • begin
  • result.x:=GetDeviceCaps(Handle, LOGPIXELSX);
  • result.y:=GetDeviceCaps(Handle, LOGPIXELSY);
  • result.x:=pt.x*result.x div 254;
  • result.y:=pt.y*result.y div 254;
  • end;
  • function TMMCanvas.ConvertRect(rect:trect):TRect;
  • var
  • lpx,lpy:integer;
  • begin
  • lpx:=GetDeviceCaps(Handle, LOGPIXELSX);
  • lpy:=GetDeviceCaps(Handle, LOGPIXELSY);
  • result.Left:=rect.Left*lpx div 254;
  • result.Top:=rect.Top*lpy div 254;
  • result.right:=rect.right*lpx div 254;
  • result.bottom:=rect.bottom*lpy div 254;
  • end;
  • constructor TMMCanvas.Create;
  • begin
  • inherited Create;
  • end;
  • destructor TMMCanvas.Destroy;
  • begin
  • inherited Destroy;
  • end;
  • procedure TMMCanvas.MMArc(X1, Y1, X2, Y2, X3, Y3, X4, Y4: Integer);
  • begin
  • x1:=convertx(x1); y1:=converty(y1);
  • x2:=convertx(x2); y2:=converty(y2);
  • x3:=convertx(x3); y3:=converty(y3);
  • x4:=convertx(x4); y4:=converty(y4);
  • Arc( X1, Y1, X2, Y2, X3, Y3, X4, Y4);
  • end;
  • procedure TMMCanvas.MMBrushCopy(Const Dest: TRect; Bitmap: TBitmap; Const Source: TRect; Color: TColor);
  • begin
  • BrushCopy(convertrect(dest), Bitmap, convertrect(source), Color);
  • end;
  • procedure TMMCanvas.MMChord(X1, Y1, X2, Y2, X3, Y3, X4, Y4: Integer);
  • begin
  • x1:=convertx(x1); y1:=converty(y1);
  • x2:=convertx(x2); y2:=converty(y2);
  • x3:=convertx(x3); y3:=converty(y3);
  • x4:=convertx(x4); y4:=converty(y4);
  • Chord(X1, Y1, X2, Y2, X3, Y3, X4, Y4);
  • end;
  • procedure TMMCanvas.MMCopyRect(Const Dest: TRect; Canvas: TCanvas;Const Source: TRect);
  • begin
  • CopyRect(convertrect(dest), Canvas, convertrect(source));
  • end;
  • procedure TMMCanvas.MMDraw(X, Y: Integer; Graphic: TGraphic);
  • begin
  • x:=convertx(x); y:=converty(y);
  • Draw(X, Y, Graphic);
  • end;
  • procedure TMMCanvas.MMDrawFocusRect(const Rect: TRect);
  • begin
  • DrawFocusRect(convertrect(Rect));
  • end;
  • procedure TMMCanvas.MMEllipse(X1, Y1, X2, Y2: Integer);
  • begin
  • x1:=convertx(x1); y1:=converty(y1);
  • x2:=convertx(x2); y2:=converty(y2);
  • Ellipse( X1, Y1, X2, Y2);
  • end;
  • procedure TMMCanvas.MMEllipse(const Rect: TRect);
  • begin
  • MMEllipse(rect.Left, rect.Top, rect.Right, rect.Bottom);
  • end;
  • procedure TMMCanvas.MMFillRect(const Rect: TRect);
  • begin
  • FillRect(convertRect(Rect));
  • end;
  • procedure TMMCanvas.MMFloodFill(X, Y: Integer; Color: TColor;
  • FillStyle: TFillStyle);
  • begin
  • x:=convertx(x); y:=converty(y);
  • FloodFill(X, Y, Color, FillStyle);
  • end;
  • procedure TMMCanvas.MMFrameRect(const Rect: TRect);
  • begin
  • FrameRect(convertRect(Rect));
  • end;
  • procedure TMMCanvas.MMLineTo(X, Y: Integer);
  • begin
  • x:=convertx(x); y:=converty(y);
  • LineTo(X, Y);
  • end;
  • procedure TMMCanvas.MMMoveTo(X, Y: Integer);
  • begin
  • x:=convertx(x); y:=converty(y);
  • MoveTo(X, Y);
  • end;
  • procedure TMMCanvas.MMPie(X1, Y1, X2, Y2, X3, Y3, X4, Y4: Integer);
  • begin
  • x1:=convertx(x1); y1:=converty(y1);
  • x2:=convertx(x2); y2:=converty(y2);
  • x3:=convertx(x3); y3:=converty(y3);
  • x4:=convertx(x4); y4:=converty(y4);
  • Pie(X1, Y1, X2, Y2, X3, Y3, X4, Y4);
  • end;
  • procedure TMMCanvas.MMPolygon(const Points: array of TPoint);
  • var
  • i:integer;
  • pt:array of tpoint;
  • begin
  • setlength(pt,high(points)+1);
  • for i:=0 to high(points) do pt[i]:=convertpoint(points[i]);
  • Polygon(pt);
  • end;
  • procedure TMMCanvas.MMPolyline(const Points: array of TPoint);
  • var
  • i:integer;
  • pt:array of tpoint;
  • begin
  • setlength(pt,high(points)+1);
  • for i:=0 to high(points) do pt[i]:=convertpoint(points[i]);
  • Polyline(pt);
  • end;
  • procedure TMMCanvas.MMPolyBezier(const Points: array of TPoint);
  • var
  • i:integer;
  • pt:array of tpoint;
  • begin
  • setlength(pt,high(points)+1);
  • for i:=0 to high(points) do pt[i]:=convertpoint(points[i]);
  • PolyBezier(pt);
  • end;
  • procedure TMMCanvas.MMPolyBezierTo(const Points: array of TPoint);
  • var
  • i:integer;
  • pt:array of tpoint;
  • begin
  • setlength(pt,high(points)+1);
  • for i:=0 to high(points) do pt[i]:=convertpoint(points[i]);
  • PolyBezierTo(pt);
  • end;
  • procedure TMMCanvas.MMRectangle(X1, Y1, X2, Y2: Integer);
  • begin
  • x1:=convertx(x1); y1:=converty(y1);
  • x2:=convertx(x2); y2:=converty(y2);
  • Rectangle(X1, Y1, X2, Y2);
  • end;
  • procedure TMMCanvas.MMRectangle(const Rect: TRect);
  • begin
  • MMRectangle(Rect.Left, Rect.Top, Rect.Right, Rect.Bottom);
  • end;
  • procedure TMMCanvas.MMRoundRect(X1, Y1, X2, Y2, X3, Y3: Integer);
  • begin
  • x1:=convertx(x1); y1:=converty(y1);
  • x2:=convertx(x2); y2:=converty(y2);
  • x3:=convertx(x3); y3:=converty(y3);
  • RoundRect(X1, Y1, X2, Y2, X3, Y3);
  • end;
  • procedure TMMCanvas.MMStretchDraw(const Rect: TRect; Graphic: TGraphic);
  • begin
  • StretchDraw(convertRect(Rect),Graphic);
  • end;
  • procedure TMMCanvas.MMTextOut(X, Y: Integer; const Text: String);
  • begin
  • x:=convertx(x); y:=converty(y);
  • TextOut( X, Y,Text);
  • end;
  • procedure TMMCanvas.MMTextRect(Rect: TRect; X, Y: Integer; const Text: string);
  • begin
  • x:=convertx(x); y:=converty(y);
  • TextRect(convertRect(Rect), X, Y, Text);
  • end;
  • function TMMCanvas.MMTextExtent(const Text: string): TSize;
  • begin
  • result:=TextExtent(Text);
  • result.cx:=invconvertx(result.cx);
  • result.cy:=invconverty(result.cy);
  • end;
  • function TMMCanvas.MMTextWidth(const Text: string): Integer;
  • begin
  • Result := TextExtent(Text).cX;
  • result:=invconvertx(result);
  • end;
  • function TMMCanvas.MMTextHeight(const Text: string): Integer;
  • begin
  • Result := TextExtent(Text).cY;
  • result:=invconverty(result);
  • end;
  • function TMMCanvas.GetPixel(X, Y: Integer): TColor;
  • begin
  • x:=convertx(x); y:=converty(y);
  • result:=pixels[x,y];
  • end;
  • procedure TMMCanvas.SetPixel(X, Y: Integer; Value: TColor);
  • begin
  • x:=convertx(x); y:=converty(y);
  • pixels[x,y]:=value;
  • end;
  • end.
unit UMMCanvas;

interface

uses windows,graphics;

type
 TMMCanvas=class(Tcanvas)
  private
    function ConvertX(x:integer):integer;
    function ConvertY(y:integer):integer;
    function InvConvertX(x:integer):integer;
    function InvConvertY(y:integer):integer;
    function ConvertPoint(pt:TPoint):TPoint;
    function ConvertRect(rect:trect):TRect;
    function GetPixel(X, Y: Integer): TColor;
    procedure SetPixel(X, Y: Integer; Value: TColor);
  protected
  public
    constructor Create;
    destructor Destroy; override;
    procedure MMArc(X1, Y1, X2, Y2, X3, Y3, X4, Y4: Integer);
    procedure MMBrushCopy(Const Dest: TRect; Bitmap: TBitmap; Const Source: TRect; Color: TColor);
    procedure MMChord(X1, Y1, X2, Y2, X3, Y3, X4, Y4: Integer);
    procedure MMCopyRect(Const Dest: TRect; Canvas: TCanvas;Const Source: TRect);
    procedure MMDraw(X, Y: Integer; Graphic: TGraphic);
    procedure MMDrawFocusRect(const Rect: TRect);
    procedure MMEllipse(X1, Y1, X2, Y2: Integer); overload;
    procedure MMEllipse(const Rect: TRect); overload;
    procedure MMFillRect(const Rect: TRect);
    procedure MMFloodFill(X, Y: Integer; Color: TColor; FillStyle: TFillStyle);
    procedure MMFrameRect(const Rect: TRect);

    procedure MMLineTo(X, Y: Integer);

    procedure MMMoveTo(X, Y: Integer);
    procedure MMPie(X1, Y1, X2, Y2, X3, Y3, X4, Y4: Integer);
    procedure MMPolygon(const Points: array of TPoint);
    procedure MMPolyline(const Points: array of TPoint);
    procedure MMPolyBezier(const Points: array of TPoint);
    procedure MMPolyBezierTo(const Points: array of TPoint);
    procedure MMRectangle(X1, Y1, X2, Y2: Integer); overload;
    procedure MMRectangle(const Rect: TRect); overload;
    procedure MMRoundRect(X1, Y1, X2, Y2, X3, Y3: Integer);
    procedure MMStretchDraw(const Rect: TRect; Graphic: TGraphic);
    function MMTextExtent(const Text: string): TSize;
    function MMTextHeight(const Text: string): Integer;
    procedure MMTextOut(X, Y: Integer; const Text: string);
    procedure MMTextRect(Rect: TRect; X, Y: Integer; const Text: string);
    function MMTextWidth(const Text: string): Integer;
    property MMPixels[X, Y: Integer]: TColor read GetPixel write SetPixel;
  published

  end;



implementation


function TMMCanvas.ConvertX(x:integer):integer;
begin
 result:=GetDeviceCaps(Handle, LOGPIXELSX);
 result:=x*result div 254;
end;

function TMMCanvas.ConvertY(y:integer):integer;
begin
 result:=GetDeviceCaps(Handle, LOGPIXELSY);
 result:=y*result div 254;
end;

function TMMCanvas.InvConvertX(x:integer):integer;
begin
 result:=GetDeviceCaps(Handle, LOGPIXELSX);
 result:=x*254 div result;
end;

function TMMCanvas.InvConvertY(y:integer):integer;
begin
 result:=GetDeviceCaps(Handle, LOGPIXELSY);
 result:=y*254 div result;
end;


function TMMCanvas.ConvertPoint(pt:TPoint):TPoint;
begin
 result.x:=GetDeviceCaps(Handle, LOGPIXELSX);
 result.y:=GetDeviceCaps(Handle, LOGPIXELSY);
 result.x:=pt.x*result.x div 254;
 result.y:=pt.y*result.y div 254;
end;

function TMMCanvas.ConvertRect(rect:trect):TRect;
var
 lpx,lpy:integer;
begin
 lpx:=GetDeviceCaps(Handle, LOGPIXELSX);
 lpy:=GetDeviceCaps(Handle, LOGPIXELSY);
 result.Left:=rect.Left*lpx div 254;
 result.Top:=rect.Top*lpy div 254;
 result.right:=rect.right*lpx div 254;
 result.bottom:=rect.bottom*lpy div 254;
end;

constructor TMMCanvas.Create;
begin
  inherited Create;
end;

destructor TMMCanvas.Destroy;
begin
  inherited Destroy;
end;

procedure TMMCanvas.MMArc(X1, Y1, X2, Y2, X3, Y3, X4, Y4: Integer);
begin
 x1:=convertx(x1);  y1:=converty(y1);
 x2:=convertx(x2);  y2:=converty(y2);
 x3:=convertx(x3);  y3:=converty(y3);
 x4:=convertx(x4);  y4:=converty(y4);
 Arc( X1, Y1, X2, Y2, X3, Y3, X4, Y4);
end;

procedure TMMCanvas.MMBrushCopy(Const Dest: TRect; Bitmap: TBitmap; Const Source: TRect; Color: TColor);
begin
 BrushCopy(convertrect(dest), Bitmap, convertrect(source), Color);
end;

procedure TMMCanvas.MMChord(X1, Y1, X2, Y2, X3, Y3, X4, Y4: Integer);
begin
 x1:=convertx(x1);  y1:=converty(y1);
 x2:=convertx(x2);  y2:=converty(y2);
 x3:=convertx(x3);  y3:=converty(y3);
 x4:=convertx(x4);  y4:=converty(y4);
 Chord(X1, Y1, X2, Y2, X3, Y3, X4, Y4);
end;

procedure TMMCanvas.MMCopyRect(Const Dest: TRect; Canvas: TCanvas;Const Source: TRect);
begin
 CopyRect(convertrect(dest), Canvas, convertrect(source));
end;

procedure TMMCanvas.MMDraw(X, Y: Integer; Graphic: TGraphic);
begin
  x:=convertx(x);  y:=converty(y);
  Draw(X, Y, Graphic);
end;

procedure TMMCanvas.MMDrawFocusRect(const Rect: TRect);
begin
 DrawFocusRect(convertrect(Rect));
end;

procedure TMMCanvas.MMEllipse(X1, Y1, X2, Y2: Integer);
begin
 x1:=convertx(x1);  y1:=converty(y1);
 x2:=convertx(x2);  y2:=converty(y2);
 Ellipse( X1, Y1, X2, Y2);
end;

procedure TMMCanvas.MMEllipse(const Rect: TRect);
begin
 MMEllipse(rect.Left, rect.Top, rect.Right, rect.Bottom);
end;

procedure TMMCanvas.MMFillRect(const Rect: TRect);
begin
 FillRect(convertRect(Rect));
end;

procedure TMMCanvas.MMFloodFill(X, Y: Integer; Color: TColor;
  FillStyle: TFillStyle);
begin
 x:=convertx(x);  y:=converty(y);
 FloodFill(X, Y, Color, FillStyle);
end;

procedure TMMCanvas.MMFrameRect(const Rect: TRect);
begin
 FrameRect(convertRect(Rect));
end;


procedure TMMCanvas.MMLineTo(X, Y: Integer);
begin
 x:=convertx(x);  y:=converty(y);
 LineTo(X, Y);
end;


procedure TMMCanvas.MMMoveTo(X, Y: Integer);
begin
 x:=convertx(x);  y:=converty(y);
 MoveTo(X, Y);
end;

procedure TMMCanvas.MMPie(X1, Y1, X2, Y2, X3, Y3, X4, Y4: Integer);
begin
 x1:=convertx(x1);  y1:=converty(y1);
 x2:=convertx(x2);  y2:=converty(y2);
 x3:=convertx(x3);  y3:=converty(y3);
 x4:=convertx(x4);  y4:=converty(y4);
 Pie(X1, Y1, X2, Y2, X3, Y3, X4, Y4);
end;


procedure TMMCanvas.MMPolygon(const Points: array of TPoint);
var
 i:integer;
 pt:array of tpoint;
begin
 setlength(pt,high(points)+1);
 for i:=0 to high(points) do pt[i]:=convertpoint(points[i]);
 Polygon(pt);
end;

procedure TMMCanvas.MMPolyline(const Points: array of TPoint);
var
 i:integer;
 pt:array of tpoint;
begin
 setlength(pt,high(points)+1);
 for i:=0 to high(points) do pt[i]:=convertpoint(points[i]);
 Polyline(pt);
end;

procedure TMMCanvas.MMPolyBezier(const Points: array of TPoint);
var
 i:integer;
 pt:array of tpoint;
begin
 setlength(pt,high(points)+1);
 for i:=0 to high(points) do pt[i]:=convertpoint(points[i]);
 PolyBezier(pt);
end;

procedure TMMCanvas.MMPolyBezierTo(const Points: array of TPoint);
var
 i:integer;
 pt:array of tpoint;
begin
 setlength(pt,high(points)+1);
 for i:=0 to high(points) do pt[i]:=convertpoint(points[i]);
 PolyBezierTo(pt);
end;

procedure TMMCanvas.MMRectangle(X1, Y1, X2, Y2: Integer);
begin
 x1:=convertx(x1);  y1:=converty(y1);
 x2:=convertx(x2);  y2:=converty(y2);
 Rectangle(X1, Y1, X2, Y2);
end;

procedure TMMCanvas.MMRectangle(const Rect: TRect);
begin
 MMRectangle(Rect.Left, Rect.Top, Rect.Right, Rect.Bottom);
end;

procedure TMMCanvas.MMRoundRect(X1, Y1, X2, Y2, X3, Y3: Integer);
begin
 x1:=convertx(x1);  y1:=converty(y1);
 x2:=convertx(x2);  y2:=converty(y2);
 x3:=convertx(x3);  y3:=converty(y3);
 RoundRect(X1, Y1, X2, Y2, X3, Y3);
end;

procedure TMMCanvas.MMStretchDraw(const Rect: TRect; Graphic: TGraphic);
begin
 StretchDraw(convertRect(Rect),Graphic);
end;

procedure TMMCanvas.MMTextOut(X, Y: Integer; const Text: String);
begin
 x:=convertx(x);  y:=converty(y);
 TextOut( X, Y,Text);
end;

procedure TMMCanvas.MMTextRect(Rect: TRect; X, Y: Integer; const Text: string);
begin
 x:=convertx(x);  y:=converty(y);
 TextRect(convertRect(Rect), X, Y, Text);
end;

function TMMCanvas.MMTextExtent(const Text: string): TSize;
begin
 result:=TextExtent(Text);
 result.cx:=invconvertx(result.cx);
 result.cy:=invconverty(result.cy);
end;

function TMMCanvas.MMTextWidth(const Text: string): Integer;
begin
  Result := TextExtent(Text).cX;
  result:=invconvertx(result);
end;

function TMMCanvas.MMTextHeight(const Text: string): Integer;
begin
  Result := TextExtent(Text).cY;
 result:=invconverty(result);
end;

function TMMCanvas.GetPixel(X, Y: Integer): TColor;
begin
  x:=convertx(x);  y:=converty(y);
  result:=pixels[x,y];
end;

procedure TMMCanvas.SetPixel(X, Y: Integer; Value: TColor);
begin
  x:=convertx(x);  y:=converty(y);
  pixels[x,y]:=value;
end;

end.

 Conclusion

Je joint un petit programme de test qui fait pas grand chose en dehors de dessiner trois gribouillons soit dans un TImage, soit sur une imprimante.
Un carré de 10cm de côté, une ellipse de 1*2cm et un bout de texte de 1cm de hauteur.

 Fichier Zip

Les Membres Club peuvent télécharger directement un fichier contenu dans le zip sans télécharger le zip en entier !

Télécharger le zip


 Historique

02 février 2008 19:33:59 :
ajout d'un exemple dans un zip

 Sources du même auteur

Source avec Zip Source avec une capture THREAD ET BITMAP (DESSIN AU CRAYON)
Source avec Zip Source avec une capture ÉCRAN DE VEILLE FEU D'ARTIFICE
Source avec Zip Source avec une capture MESSAGE EN FEU D'ARTIFICE
Source avec Zip Source avec une capture ENCORE LOUPÉ
Source avec Zip Source avec une capture JEU LOGICOLOR

 Sources de la même categorie

Source avec Zip Source avec une capture EFFET VITRE ET THUMBNAILS SOUS VISTA par Bacterius
Source avec Zip Source avec une capture ANAGLYPHEUR OU COMMENT VOIR EN RELIEF LES STÉRÉOSCOPES ANCES... par jfs59
Source avec Zip Source avec une capture DÉFORMER UNE IMAGE AUX DIMENSIONS D'UN QUADRANGLE QUELCONQUE... par FFCAST
Source avec Zip Source avec une capture THREAD ET BITMAP (DESSIN AU CRAYON) par barbichette
Source avec Zip Source avec une capture ÉCRAN DE VEILLE FEU D'ARTIFICE par barbichette

 Sources en rapport avec celle ci

Source avec Zip Source avec une capture COMPOSANT TDESKTOP par Bacterius
Source avec Zip Source avec une capture CERCLE PASSANT PAR 3 POINTS (2° VERSION) par John Dogget
Source avec Zip Source avec une capture SÉLECTIONNNER, DÉPLACER, ÉTIRER DES LIGNES DANS UN CANVAS. par Caribensila
Source avec Zip CODEDLT par fbalien
Source avec Zip Source avec une capture UTILISATION DE CANVAS.RECTANGLE/ROUNDRECT/ELLIPSE DANS LA LI... par MAURICIO

Commentaires et avis

Commentaire de cantador le 02/02/2008 18:54:18

salut barbichette,
un petit exemple de ce qu'on peut envoyer à l'imprimante afin de montrer en quoi cette classe peut s'avérer utile.
Dans un autre style, j'aime bcp tes anims..

Commentaire de f0xi le 02/02/2008 18:57:52 administrateur CS

Un zip! des femmes et d'la biere nom de dieu!
Moi je veux un zip! pour par copier-coller comme un con!
Un zip! des femmes c'est ça qui'm'rend heureux!
Que'l'diable nous emporte, mais ce s'rait franchement mieux!

Commentaire de MAURICIO le 04/02/2008 14:47:13

Salut Barbichette,

ça fait longtemps que l 'on a pas de tes nouvelles?!

Par contre, ça fait plaisir cette source, j' y ai déjà pensé, comme quoi ... Ça va me faire gagner du temps.

Par contre, je rejoins les autres, une petite source aurait été mieux!

@florenth: GDI+ ??? tu peux m' en dire plus? demo? etc .. ?

A+

Commentaire de Caribensila le 04/02/2008 17:08:43

Salut,

Peut-être complémentaire :

http://www.codyx.org/snippet_convertir-distance-sur-votre-ecran-pixels-millimetres_464.aspx

Commentaire de MAURICIO le 28/02/2008 17:33:50

Salut Barbichette,

je suis en pleine étude de ta unit,
que fait au juste la fonction InvConvertX ?

Merci d' avance ...

Commentaire de MAURICIO le 28/02/2008 18:05:14

Ok ok, j' avais déjà compris !   lol
Je me suis couché tard ...
Merci quand même lol

Commentaire de MAURICIO le 29/02/2008 12:55:39

Salut Barbichette,

j' ai fini d' écrire ma propre unit qui est pompée à 99% sur la tienne.
J' ai juste changé TMMCanvas par TDMMCanvas: DMM veut dire 10ème de milimètre et changé le nom des propriétés/fonctions.

J' ai aussi crée :
property  DMMPixels[X, Y: Integer]: TColor read DMMGetPixel write DMMSetPixel;

Bon, je te poste ma Unit, ce sera plus simple (je vais pas faire un code sur une source copiée à 99%):

unit Tc_DmmCanvas;

interface

uses windows,graphics;

type
  TDMMCanvas=class(Tcanvas)
  private
    function  DMMGetPixel(X, Y: Integer): TColor;
    procedure DMMSetPixel(X, Y: Integer; Value: TColor);
    function  DMMGetFontHeight: Integer;
    procedure DMMSetFontHeight(Value: Integer);
  protected
  public
    constructor Create;
    destructor Destroy; override;

    // Fonctions de conversion en 10ème de milimètres :
    function  PxToDmm_X(x:integer): integer;
    function  PxToDmm_Y(y:integer): integer;
    
    // Fonctions de conversion en pixels :
    function  DmmToPx_X(x:integer): integer;
    function  DmmToPx_Y(y:integer): integer;
    function  DmmToPx_Point(pt:TPoint): TPoint;
    function  DmmToPx_Rect(rect:trect): TRect;

    // Fonctions de dessin en 10ème de milimètres :
    procedure DMMArc(X1, Y1, X2, Y2, X3, Y3, X4, Y4: Integer);
    procedure DMMBrushCopy(Const Dest: TRect; Bitmap: TBitmap; Const Source: TRect; Color: TColor);
    procedure DMMChord(X1, Y1, X2, Y2, X3, Y3, X4, Y4: Integer);
    procedure DMMCopyRect(Const Dest: TRect; Canvas: TCanvas;Const Source: TRect);
    procedure DMMDraw(X, Y: Integer; Graphic: TGraphic);
    procedure DMMDrawFocusRect(const Rect: TRect);
    procedure DMMEllipse(X1, Y1, X2, Y2: Integer); overload;
    procedure DMMEllipse(const Rect: TRect); overload;
    procedure DMMFillRect(const Rect: TRect);
    procedure DMMFloodFill(X, Y: Integer; Color: TColor; FillStyle: TFillStyle);
    procedure DMMFrameRect(const Rect: TRect);
    procedure DMMLineTo(X, Y: Integer);
    procedure DMMMoveTo(X, Y: Integer);
    procedure DMMPie(X1, Y1, X2, Y2, X3, Y3, X4, Y4: Integer);
    procedure DMMPolygon(const Points: array of TPoint);
    procedure DMMPolyline(const Points: array of TPoint);
    procedure DMMPolyBezier(const Points: array of TPoint);
    procedure DMMPolyBezierTo(const Points: array of TPoint);
    procedure DMMRectangle(X1, Y1, X2, Y2: Integer); overload;
    procedure DMMRectangle(const Rect: TRect); overload;
    procedure DMMRoundRect(X1, Y1, X2, Y2, X3, Y3: Integer);
    procedure DMMStretchDraw(const Rect: TRect; Graphic: TGraphic);
    function  DMMTextExtent(const Text: string): TSize;    // Largeur et hauteur en DMM du texte dans la police actuelle
    function  DMMTextHeight(const Text: string): Integer;
    procedure DMMTextOut(X, Y: Integer; const Text: string);
    procedure DMMTextRect(Rect: TRect; X, Y: Integer; const Text: string);
    function  DMMTextWidth(const Text: string): Integer;
    property  DMMFontHeight: Integer read DMMGetFontHeight write DMMSetFontHeight;
    property  DMMPixels[X, Y: Integer]: TColor read DMMGetPixel write DMMSetPixel;
  published

  end;



implementation


constructor TDMMCanvas.Create;
begin
  inherited Create;
end;

destructor TDMMCanvas.Destroy;
begin
  inherited Destroy;
end;

// Convertir en 10ème de milimètres ...
function TDMMCanvas.PxToDmm_X(x: integer):integer;
begin
  result := GetDeviceCaps(Handle, LOGPIXELSX);
  result := x * 254 div result;
end;

// Convertir en 10ème de milimètres ...
function TDMMCanvas.PxToDmm_Y(y: integer):integer;
begin
  result := GetDeviceCaps(Handle, LOGPIXELSY);
  result := y * 254 div result;
end;

// Convertir en pixels ...
function TDMMCanvas.DmmToPx_X(x: integer):integer;
begin
  result := GetDeviceCaps(Handle, LOGPIXELSX);  // Récupérer le nombre de points par pouce du Canvas ...
  result := x * result div 254;
end;

// Convertir en pixels ...
function TDMMCanvas.DmmToPx_Y(y: integer):integer;
begin
  result := GetDeviceCaps(Handle, LOGPIXELSY);
  result := y * result div 254;
end;

// Convertir en pixels :
function TDMMCanvas.DmmToPx_Point(pt: TPoint):TPoint;
begin
  result.x := GetDeviceCaps(Handle, LOGPIXELSX);
  result.y := GetDeviceCaps(Handle, LOGPIXELSY);
  result.x := pt.x * result.x div 254;
  result.y := pt.y * result.y div 254;
end;

function TDMMCanvas.DmmToPx_Rect(rect: TRect):TRect;
var lpx, lpy:integer;
begin
  lpx := GetDeviceCaps(Handle, LOGPIXELSX);
  lpy := GetDeviceCaps(Handle, LOGPIXELSY);

  result.Left := rect.Left * lpx div 254;
  result.Top := rect.Top * lpy div 254;
  result.right := rect.right * lpx div 254;
  result.bottom := rect.bottom * lpy div 254;
end;

procedure TDMMCanvas.DMMArc(X1, Y1, X2, Y2, X3, Y3, X4, Y4: Integer);
begin
  x1 := DmmToPx_X(x1);  y1 := DmmToPx_Y(y1);
  x2 := DmmToPx_X(x2);  y2 := DmmToPx_Y(y2);
  x3 := DmmToPx_X(x3);  y3 := DmmToPx_Y(y3);
  x4 := DmmToPx_X(x4);  y4 := DmmToPx_Y(y4);
  Arc( X1, Y1, X2, Y2, X3, Y3, X4, Y4);
end;

procedure TDMMCanvas.DMMBrushCopy(Const Dest: TRect; Bitmap: TBitmap; Const Source: TRect; Color: TColor);
begin
  BrushCopy(DmmToPx_Rect(dest), Bitmap, DmmToPx_Rect(source), Color);
end;

procedure TDMMCanvas.DMMChord(X1, Y1, X2, Y2, X3, Y3, X4, Y4: Integer);
begin
  x1 := DmmToPx_X(x1);  y1 := DmmToPx_Y(y1);
  x2 := DmmToPx_X(x2);  y2 := DmmToPx_Y(y2);
  x3 := DmmToPx_X(x3);  y3 := DmmToPx_Y(y3);
  x4 := DmmToPx_X(x4);  y4 := DmmToPx_Y(y4);
  Chord(X1, Y1, X2, Y2, X3, Y3, X4, Y4);
end;

procedure TDMMCanvas.DMMCopyRect(Const Dest: TRect; Canvas: TCanvas;Const Source: TRect);
begin
  CopyRect(DmmToPx_Rect(dest), Canvas, DmmToPx_Rect(source));
end;

procedure TDMMCanvas.DMMDraw(X, Y: Integer; Graphic: TGraphic);
begin
  x := DmmToPx_X(x);  y := DmmToPx_Y(y);
  Draw(X, Y, Graphic);
end;

procedure TDMMCanvas.DMMDrawFocusRect(const Rect: TRect);
begin
  DrawFocusRect(DmmToPx_Rect(Rect));
end;

procedure TDMMCanvas.DMMEllipse(X1, Y1, X2, Y2: Integer);
begin
  x1 := DmmToPx_X(x1);  y1 := DmmToPx_Y(y1);
  x2 := DmmToPx_X(x2);  y2 := DmmToPx_Y(y2);
  Ellipse( X1, Y1, X2, Y2);
end;

procedure TDMMCanvas.DMMEllipse(const Rect: TRect);
begin
  DMMEllipse(rect.Left, rect.Top, rect.Right, rect.Bottom);
end;

procedure TDMMCanvas.DMMFillRect(const Rect: TRect);
begin
  FillRect(DmmToPx_Rect(Rect));
end;

procedure TDMMCanvas.DMMFloodFill(X, Y: Integer; Color: TColor;
  FillStyle: TFillStyle);
begin
  x := DmmToPx_X(x);  y := DmmToPx_Y(y);
  FloodFill(X, Y, Color, FillStyle);
end;

procedure TDMMCanvas.DMMFrameRect(const Rect: TRect);
begin
  FrameRect(DmmToPx_Rect(Rect));
end;


procedure TDMMCanvas.DMMLineTo(X, Y: Integer);
begin
  x := DmmToPx_X(x);  y := DmmToPx_Y(y);
  LineTo(X, Y);
end;


procedure TDMMCanvas.DMMMoveTo(X, Y: Integer);
begin
  x := DmmToPx_X(x);  y := DmmToPx_Y(y);
  MoveTo(X, Y);
end;

procedure TDMMCanvas.DMMPie(X1, Y1, X2, Y2, X3, Y3, X4, Y4: Integer);
begin
  x1 := DmmToPx_X(x1);  y1 := DmmToPx_Y(y1);
  x2 := DmmToPx_X(x2);  y2 := DmmToPx_Y(y2);
  x3 := DmmToPx_X(x3);  y3 := DmmToPx_Y(y3);
  x4 := DmmToPx_X(x4);  y4 := DmmToPx_Y(y4);
  Pie(X1, Y1, X2, Y2, X3, Y3, X4, Y4);
end;


procedure TDMMCanvas.DMMPolygon(const Points: array of TPoint);
var
  i:integer;
  pt:array of tpoint;
begin
  setlength(pt, high(points) + 1);

  for i := 0 to high(points) do
    pt[i] := DmmToPx_Point(points[i]);

  Polygon(pt);
end;

procedure TDMMCanvas.DMMPolyline(const Points: array of TPoint);
var
  i:integer;
  pt:array of tpoint;
begin
  setlength(pt, high(points)+1);

  for i := 0 to high(points) do
    pt[i] := DmmToPx_Point(points[i]);

  Polyline(pt);
end;

procedure TDMMCanvas.DMMPolyBezier(const Points: array of TPoint);
var
  i:integer;
  pt:array of tpoint;
begin
  setlength(pt, high(points) + 1);

  for i := 0 to high(points) do
    pt[i] := DmmToPx_Point(points[i]);
    
  PolyBezier(pt);
end;

procedure TDMMCanvas.DMMPolyBezierTo(const Points: array of TPoint);
var
  i:integer;
  pt:array of tpoint;
begin
  setlength(pt, high(points) + 1);

  for i := 0 to high(points) do
    pt[i] := DmmToPx_Point(points[i]);

  PolyBezierTo(pt);
end;

procedure TDMMCanvas.DMMRectangle(X1, Y1, X2, Y2: Integer);
begin
  x1 := DmmToPx_X(x1);  y1 := DmmToPx_Y(y1);
  x2 := DmmToPx_X(x2);  y2 := DmmToPx_Y(y2);
  Rectangle(X1, Y1, X2, Y2);
end;

procedure TDMMCanvas.DMMRectangle(const Rect: TRect);
begin
  DMMRectangle(Rect.Left, Rect.Top, Rect.Right, Rect.Bottom);
end;

procedure TDMMCanvas.DMMRoundRect(X1, Y1, X2, Y2, X3, Y3: Integer);
begin
  x1 := DmmToPx_X(x1);  y1 := DmmToPx_Y(y1);
  x2 := DmmToPx_X(x2);  y2 := DmmToPx_Y(y2);
  x3 := DmmToPx_X(x3);  y3 := DmmToPx_Y(y3);
  RoundRect(X1, Y1, X2, Y2, X3, Y3);
end;

procedure TDMMCanvas.DMMStretchDraw(const Rect: TRect; Graphic: TGraphic);
begin
  StretchDraw(DmmToPx_Rect(Rect), Graphic);
end;

procedure TDMMCanvas.DMMTextOut(X, Y: Integer; const Text: String);
begin
  x := DmmToPx_X(x);  y := DmmToPx_Y(y);
  TextOut(X, Y, Text);
end;

procedure TDMMCanvas.DMMTextRect(Rect: TRect; X, Y: Integer; const Text: string);
begin
  x := DmmToPx_X(x);  y := DmmToPx_Y(y);
  TextRect(DmmToPx_Rect(Rect), X, Y, Text);
end;

function TDMMCanvas.DMMTextExtent(const Text: string): TSize;
begin
  result := TextExtent(Text);
  result.cx := PxToDmm_X(result.cx);
  result.cy := PxToDmm_Y(result.cy);
end;

function TDMMCanvas.DMMTextWidth(const Text: string): Integer;
begin
  result := TextExtent(Text).cX;
  result := PxToDmm_X(result);
end;

function TDMMCanvas.DMMTextHeight(const Text: string): Integer;
begin
  Result := TextExtent(Text).cY;
  Result := PxToDmm_Y(result);
end;

function TDMMCanvas.DMMGetPixel(X, Y: Integer): TColor;
begin
  x := DmmToPx_X(x);  y := DmmToPx_Y(y);
  result := pixels[x,y];
end;

procedure TDMMCanvas.DMMSetPixel(X, Y: Integer; Value: TColor);
begin
  x := DmmToPx_X(x);  y := DmmToPx_Y(y);
  pixels[x,y] := value;
end;

function TDMMCanvas.DMMGetFontHeight: Integer;
begin
  result := Font.Height * 254 div Font.PixelsPerInch;
end;

procedure TDMMCanvas.DMMSetFontHeight(Value: Integer);
begin
  Font.Height := Value * Font.PixelsPerInch div 254;
end;

end.

En tout cas je te remercie, tu m' as fais gagné du temps!!!
Bravo encore une fois, j' attends tes prochaines sources avec une certaine impatience ...

A+

Commentaire de MAURICIO le 29/02/2008 12:57:02

Oups, je voulais dire que j' ai ajouté ceci:
property  DMMFontHeight: Integer read DMMGetFontHeight write DMMSetFontHeight;

On l' utilise ainsi:
c.DMMFontHeight := 900;  // 9 cm de hauteur ...

A+

Commentaire de Jean-Pierre le 21/09/2009 17:35:35

Salut tout le monde,

Merci aux contributeurs de nous donner ces précieuses ressources.

Voilà, j'ai une chose particulière qui me gratouille...

Sur la démo, si je passe par une impression (BeginDoc, etc.) : la mesure est absolument correcte.

Par contre, si je passe par le TImage afin de mesurer la string, là alors le résultat me donne quelques millimètres de plus.

procedure TForm1.btnTestClick(Sender: TObject);
var
c: TMMCanvas;
s: String;
begin
  c := tmmcanvas(image1.canvas);

  s := 'Ceci est un petit test de la classe TMMCanvas';

  c.font.name  := 'Nyala'; // 'courier new';
  c.font.Size  := 12;
  c.Font.Style := [fsBold];

  ShowMessage(IntToStr(C.MMTextWidth(s)));
end;

Est-il possible d'obtenir la longueur sans passer par une impression ; telle est la question que je me pose.

Merci beaucoup de tenter d'éclaircir ce point précis.

A moins qu'une telle possibilité existe en cette source de Barbichette.

J'espère que je poste au bon endroit, puisque cette question est en étroite relation avec cette page...

Commentaire de barbichette le 21/09/2009 18:59:01

va voir ici,
http://www.delphifr.com/forum/sujet-D7-LISTER-RESOLUTION-IMPRIMANTE_919484.aspx
La solution, c'est d'avoir les infos sur l'imprimante, puis avec la résolution (en point par pouce) on peut retrouver la taille d'impression d'un dessin.
taille en mm=(taille en pixels)/(résolution*.254)
ou
taille en pouce=(taille en pixels)/résolution

voilà

Commentaire de Jean-Pierre le 21/09/2009 20:03:11 9/10

Barbichette merci, là, je comprends mieux ce qu'il manquait à mon raisonnement.

@+ ;-)

Commentaire de barbichette le 22/09/2009 17:36:25

Oupss... erreur...

taille en mm=(taille en pixels)*25.4/résolution
ou
taille en pouce=(taille en pixels)/résolution
c'est mieux...

Commentaire de Jean-Pierre le 22/09/2009 19:02:29

Merci Barbichette de ta précision rectificative.

Mais après des tests; là je vais devenir complètement chèvre lol !

Car sur ton zip de démo, la string "Ceci est un petit test de la classe TMMCanvas" (en impression) me donne le result de 742 pixels pour 74 millimètres imprimés.

Or suivant ton indication suivant ton message juste ci-dessus :
(taille en mm=(taille en pixels)*25.4/résolution)

Soit :
...
  SizeMM := (742) * 25.4 / 600;
...

Ça me donne 31 mm en résultat. Oui seulement 31 millimètres pour 742 pixels.

Je précise que j'ai mis en dur pour simplifier les pixels du string = 742
Idem en dur la résolution de mon imprimante = 600
Idem ai affecté : le même nom, taille, size et style de fonte.


Je me demande bien qu'est-ce qui cloche...

@+  ;-)

Commentaire de Jean-Pierre le 22/09/2009 19:34:52

Oupssss , pas un point en trop ?

taille en mm = (taille en pixels) * 254 / résolution // 254 et non 25.4 ?

Car là, ce serait plausible.

@+  ;-)

Commentaire de barbichette le 22/09/2009 19:38:24

ben rien...
742 pixels, avec une résolution de 600 pixels par pouce = 1.236666666
1 pouce=2.54 cm donc 1.236666*2.54 = 3.1 cm (ou 31 mm)
c'est normal....
Enfin pour moi....

Barbichette

Commentaire de Jean-Pierre le 22/09/2009 19:46:00

Si seulement ce forum avait une option rectification ou killage de message, j'aurai pu supprimer mon dernier message, juste au dessus. Ça m'aurait évité de dire une grosse bétise lol !

Barbichette, tu as sans doute raison.

Pas d'autres "grosses pointures" pour nous donner leurs avis sur cette question très intéressante ?

@+

 Ajouter un commentaire


Discussions en rapport avec ce code source dans le forum

Imprimer un imageList [ par dugueclin ] Bonjour à tous,j'ai un problème lorsque j'imprime mon StringGrid: dans la procedure OnDrawCells du StrinGrid, si la ou les cellules de Impression d'images [ par cedricbi ] Bonjour,J'ai un petit bug (ou plutot gros) dans mon programme ! J'essaye d'imprimer des images. Avec plusieurs images sur la même page. Mais 1 fo Printer.Canvas.TextOut [ par walid_kerkoub2006 ] Bonjour, Je voudrais imprimer une image avec du texte en dessus, pour celà j'ai utilisé Printer.Canvas.TextOut pour le texte et Printer.Canvas.Draw Canvas Pen Position [ par walid_kerkoub2006 ] Bonjour,Juste un autre truc je voudrais déssiner une ligne donc j'utilise Printer.Canvas.LineTo(x,y) qui est une fonction pour déssiner une ligne de l Calage imprimante Matricielle [ par couf ] Bonjour à Tous,  Je vois déja les rires de certains qui vont dire mais c'est quoi ce matérielle de Dinausaure.:-DBref il ya quelques temps j'aurais mo tous mes "printer.canvas.textout" sortent avec un cadre [ par jjnouiphp ] Bonjour. Après de nombreux essais, je n'ai toujours pas trouvé de solution à ce problème. A chaque fois que je veux imprimer un texte celui-ci est imp Ecrire sur un canvas qui a un background en dégradé [ par jderf ] Bonjour, Je souhaite écrire avec canvas.textout sur un canvas qui a un fond en dégradé (réalisé avec unité de cirec [url=http://www.delphifr.com/code Problème d'affichage d'une Image1.Canvas.Pen.Mode [ par cincap ] Bonsoir à toutes et à tous,Je dispose de deux fiche, sur la 1ère (formvisu) je charge une photo dans un Timage et j'ai un Tprintersetupdialog, sur la TImageList, TImage et Transparence [ par JulioDelphi ] Bonsoir, J'ai un soucis de transparence, voila le bazar : Je pose une TImage, je vais peindre dessus grace au .Canvas Je pose un TImageList. Elle co Problème impression couleur [ par kacola ] Bonjour, j'ai une imprimante couleur Canon MP780 et une Laser N&B Canon (qui est par défaut),Je souhaite imprimer une image (un jpeg) en couleur,


Nos sponsors


Sondage...

Comparez les prix

CalendriCode

Février 2010
LMMJVSD
1234567
891011121314
15161718192021
22232425262728

Consulter la suite du CalendriCode

 
Développement réalisé par Nicolas SOREL (Nix) avec l'aide de : Cyril DURAND et Emmanuel (EBArtSoft), Merci à Vincent pour ses précieux conseils.
CodeS-SourceS.com© Toute reproduction même partielle est interdite sauf accord écrit du Webmaster
CodeS-SourceS.com© est une marque déposée tous droits réservés

Google Coop CodeS-SourceS Google Coop CodeS-SourceS
Temps d'éxécution de la page : 0,640 sec (3)

Nous contacter | Annoncer sur CodeS-SourceS | Mentions légales