Question simple:
comment dessiner un petit disque coloré en rouge par exemple qui soit le plus régulier possible. sans cannelures. et sans sortir non plus la batterie anti-aliasing. les methodes du canvas ne sont jamais nickel.
merci
Question simple:
comment dessiner un petit disque coloré en rouge par exemple qui soit le plus régulier possible. sans cannelures. et sans sortir non plus la batterie anti-aliasing. les methodes du canvas ne sont jamais nickel.
merci
Tu veux sans doute parler de quelque chose de mieux qu'un simple TShape en stCircle ?
même en utilisant le GDI, ce n'est propre :
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116 unit Ugraph; interface uses Windows,graphics,Extctrls,types,classes,controls,math; type reel=extended; type Trpoint=record x,y:reel; end; type Tgraph=class(Tbitmap) public constructor Create(w,h:integer);reintroduce;overload; end; type Tgraphique=class(Timage) private xmin,ymin,xmax,ymax:reel; graph:Tgraph; public constructor Create(w,h:integer;x1,x2,y1,y2:reel;par:Twincontrol;aowner:Tcomponent);reintroduce;overload; destructor Destroy;override; procedure obturation(cl:Tcolor); procedure disque(xo,yo,R:reel;cl:Tcolor); procedure initransfo; procedure charge; end; implementation const M:integer=1000000; constructor Tgraph.Create(w,h:integer); begin inherited create; width:=w; height:=h; end; constructor Tgraphique.Create(w,h:integer;x1,x2,y1,y2:reel;par:Twincontrol;aowner:Tcomponent); begin inherited create(aowner); parent:=par; visible:=false; width:=w; height:=h; xmin:=x1; xmax:=x2; ymin:=y1; ymax:=y2; graph:=Tgraph.create(w,h); end; procedure Tgraphique.initransfo; var XFrm:XForm; begin xFrm.eM11 :=width/(M*(xmax-xmin)); xFrm.eM22 :=-height/(M*(ymax-ymin)); xFrm.eM12 := 0; xFrm.eM21 := 0; xFrm.eDx :=-width*xmin/(xmax-xmin); xFrm.eDy :=ymax*height/(ymax-ymin); SetGraphicsMode(graph.Canvas.Handle, GM_ADVANCED); setworldtransform(graph.canvas.handle,xFrm); end; procedure Tgraphique.obturation(cl:Tcolor); var r:Trect; begin with r do begin left:=round(M*xmin); top:=round(M*ymax); right:=round(M*xmax); bottom:=round(M*ymin); end; with graph.canvas do begin brush.Color:=cl; fillrect(r); end; end; procedure Tgraphique.charge; Begin picture.Bitmap:=graph; end; procedure TGraphique.disque(xo,yo,R:reel;cl:Tcolor);//si orthonormé var pt:Tpoint; begin pt:=point(round(M*xo),round(M*yo)); with graph.canvas do begin pen.Color:=cl; brush.Color:=cl; ellipse(rect(pt.X-round(R*M),pt.Y-round(R*M),pt.X+round(R*M),pt.Y+round(R*M))); end; end; destructor TGraphique.Destroy; begin graph.Free; inherited; end; end.Je suis passé en coordonnées réelles en dessinant dans le bitmap d'un TImage. Je n'arrive pas à utiliser le GDI directement en dérivant un TBitmap.
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55 unit Unit1; interface uses Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms, Dialogs,UGraph; type TForm1 = class(TForm) procedure FormCreate(Sender: TObject); procedure FormClose(Sender: TObject; var Action: TCloseAction); procedure FormPaint(Sender: TObject); private { Déclarations privées } mondessin:Tgraphique; public { Déclarations publiques } end; var Form1: TForm1; implementation {$R *.dfm} procedure TForm1.FormClose(Sender: TObject; var Action: TCloseAction); begin mondessin.destroy; end; procedure TForm1.FormCreate(Sender: TObject); begin setbounds(0,0,screen.Width div 2,screen.Width div 2); position:=poscreencenter; formstyle:=fsstayontop; mondessin:=TGraphique.Create(clientwidth,clientheight,-5,5,-5,5,self,self); end; procedure TForm1.FormPaint(Sender: TObject); begin with mondessin do begin initransfo; obturation(clwhite); disque(0,0,3,clred); charge; end; canvas.Draw(0,0,mondessin.Picture.bitmap); end; end.
ça ne marche pas...
et même en faisant ça, c'est encore cannelé....
Regarde à : Comment lisser un objet dessiné dans un TBitmap ?
(Un peu plus bas que la moitié de page)
Ça devrait être intéressant je pense.
@+
plusieurs possibilités
Graphics32
GDI+
un bitmap précalculée
une image calculée dynamiquement, pour cela il existe une méthode simple pas très difficile à coder mais peu performante (ça suffit parfois):
- tu veux un disque de 10x10 pixels
- tu crées un bitmap de 20x20 pixels
- tu dessines dessus un disque de 20x20 de façon traditionnelle
- tu créés un bitmap de 10x10 pixels (ou tu réutilises un quart du bitmap existant)
- pour les pixels[x,y] de 0..9 tu calcules leur couleur en faisant la moyenne des 4 pixels [2*x+i,2*y+i] avec i de 0 à 1
- pour cela tu décomposes en R,G,B les pixels et tu fais la moyenne de chaque composante couleur
avec ça tu obtiens une image lissée.
au besoin du place une image de fond dans le bitmap avant opération (doublée en taille évidemment)
merci, je vais me lancer dans ta méthode. C'est toujours net et précis avec toi
merci à vous deux .
Partager