Précédent   Forum du club des développeurs et IT Pro > Autres langages > Pascal > Flash Pascal
Flash Pascal Forum d'entraide sur la création de fichiers Flash en Object Pascal
Partagez cette discussion sur d'autres réseaux sociaux : Viadeo Twitter Google Facebook Digg Delicious MySpace Yahoo
Réponse
 
Outils de la discussion
Publicité
'
Vieux 19/06/2012, 14h53   #1
Archimède
Membre émérite
 
Avatar de Archimède
 
Homme anthony
Enseignant
Inscription : avril 2005
Messages : 1 026
Détails du profil
Informations personnelles :
Nom : Homme anthony
Localisation : France, Charente Maritime (Poitou Charente)

Informations professionnelles :
Activité : Enseignant
Secteur : Enseignement

Informations forums :
Inscription : avril 2005
Messages : 1 026
Points : 975
Points : 975
Par défaut Utilisation de SetPixel

ci-joint une application :

Code :
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
 
program niveau_de_gris;
 
{$FRAME_WIDTH 520}
{$FRAME_HEIGHT 366}
{$FRAME_RATE 32}
{$BACKGROUND $FFFFFF}
{$JPEG  nom 'voeux2012.jpg'}
 
uses
  Flash8,UCursor;
 
const
       frame_width=520;
       frame_height=366 ;
type
  image = class(Movieclip)
    mybmp : BitmapData;
    Field:TextField;
    Font:TextFormat;
    constructor Create;
    procedure onKeyDown;
    Procedure onMouseMove;
  end;
 
var cur:TCursor;
 
Function GetBvalue(coul:integer):integer;
begin
 result :=coul Mod 256;
end;
 
Function GetGvalue(coul:integer):integer;
begin
 result :=floor((Coul Mod 65536)/256);
end;
 
Function GetRvalue(coul:integer):integer;
begin
 result :=Floor(Coul/65536);
end;
 
Function RGB(R,V,B:integer):integer;
begin
 result:=65536*R+256*V+B;
end;
 
 
function IntToStr3(i: Integer): string;
begin
  Result := IntToStr(i);
  if (i<100) and (i<>0) and (i>=10) then Result:='0'+Result else if (i<10) and (i<>0) then Result:='00'+Result else if i =0 then Result :='000';
end;
 
 
constructor Image.Create;
begin
 inherited Create(nil,'mymovieclip',1);
 mybmp := loadBitmap('nom');
 attachBitmap(mybmp,1,'',false);
 Font:=TextFormat.Create( 'Arial',16,$000000,True,False,False,'center');
 cur:=TCursor.create(self);
 Key.Addlistener(self);
 field:=TextField.Create(self,'codeRGB',getNextHighestDepth(),0,0,200,40);
 field.selectable:=false;
 field.setNewTextFormat(Font);
end;
 
Procedure Image.onMouseMove;
var R,V,B:integer;
    rgb:number;
begin
 rgb:=mybmp.GetPixel(_xmouse,_ymouse);
 R:=GetRValue(floor(rgb));
 V:=GetGValue(floor(rgb));
 B:=GetBValue(floor(rgb));
 Field.text:='( '+inttostr3(R)+' , '+inttostr3(V)+' , '+inttostr3(B)+' )';
 Field._x:=_xmouse-60;
 Field._y:=_ymouse-30;
end;
 
procedure Image.onKeyDown;
var i,j:integer;
    col:number;
    R,V,B,moy:integer;
begin
 For i:=0 to 520 do for j:=0 to 366 do
 begin
   col:=mybmp.GetPixel(i,j);
   R:=GetRValue(floor(col));
   V:=GetGValue(floor(col));
   B:=GetBValue(floor(col));
   moy:=Floor((R+V+B)/3);
   mybmp.SetPixel( i,j,RGB(moy,moy,moy) );
 end;
   mybmp.draw(mybmp);
end;
 
begin
 Image.create;
 stage.scaleMode :='noScale';
end.
+ UCusor

Code :
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
 
unit UCursor;
 
interface
 
uses
  Flash8,URealmovie;//uniquement pour le record TPoint...
 
const clblack=$000000;
 
type
  Mouse = external class
    class procedure addListener(listener: TObject);
    class function hide: Number;
    class function removeListener(listener: TObject): Boolean;
    class function show: Number;
  end;
 
  TCursor = class(MovieClip)
    constructor Create(mc:Textfield);
    Procedure Arrow(x1,y1,x2,y2:number;col,penw:integer);
    procedure onMouseMove;
  end;
 
implementation
 
constructor TCursor.Create(mc:TextField);
begin
  inherited Create(nil,'Cursor',getNextHighestDepth());
  Arrow(0,30,0,0,clblack,2);
  Mouse.addListener(mc);
  Mouse.Hide;
end;
 
procedure TCursor.onMouseMove;
begin
  _x :=_root._xmouse;
  _y :=_root._ymouse;
end;
 
Procedure TCursor.Arrow(x1,y1,x2,y2:number;col,penw:integer);
var i:integer;
    Norme,cX,cY: number;
    ALength,AWidth:number;
    Arrow:array of TPoint;
begin
  ALength:=10;
  AWidth:=7;
  Norme:=SQRT((x2-x1)*(x2-x1)+(y2-y1)*(y2-y1));
  if Norme=0 then Exit;
  cX:=(x2-x1)/Norme;
  cY:=(y2-y1)/Norme;
  Arrow[0]:=pt(x2,y2);
  Arrow[1]:=pt(x2-cX*ALength+cY*AWidth,y2-cY*ALength-cX*AWidth);
  Arrow[2]:=pt(x2-cX*ALength-cY*AWidth,y2-cY*ALength+cX*AWidth);
  Arrow[3]:=pt(x2,y2);
 
  Linestyle(penw,col);
  BeginFill(col);
  Moveto(x1,y1);
  Lineto(x2,y2);
  Moveto(arrow[0].x,arrow[0].y);
  for i:=1 to 3 do lineto(arrow[i].x,arrow[i].y);
  Endfill();
end;
 
end.
Ma question est : existe-il un moyen plus rapide pour changer la couleur de la photo... un scanline spécial flashpascal ?

Anthony
Fichiers attachés
Type de fichier : swf Pniveau_de_gris.swf (27,7 Ko, 7 affichages)
__________________
Citation:
tout développeur plongé dans son code subit une poussée d'urticaire de bas en haut égale au poids du volume d'unités qu'il ajoute.
Archimède est déconnecté   Envoyer un message privé Réponse avec citation 00
Vieux 19/06/2012, 15h56   #2
Paul TOTH
Expert Confirmé Sénior
 
Avatar de Paul TOTH
 
Homme Paul TOTH
Freelance
Inscription : novembre 2002
Messages : 4 395
Détails du profil
Informations personnelles :
Nom : Homme Paul TOTH
Âge : 43
Localisation : Réunion

Informations professionnelles :
Activité : Freelance
Secteur : High Tech - Éditeur de logiciels

Informations forums :
Inscription : novembre 2002
Messages : 4 395
Points : 10 736
Points : 10 736
Hello,

Alors Flash possède beaucoup mieux qu'un ScanLine !

l'objet BitmapData possède un tas de méthodes très évoluées.

tu as notamment les filtres, en voici un qui n'était pas dans Flash8 et que j'ajouterais
Code :
1
2
3
4
5
6
7
8
9
 
type
  ColorMatrixFilter = external class({BitmapFilter,}flash.filters.ColorMatrixFilter)
    property matrix: array[0..19] of Number;
 
    constructor Create(matrix: array[0..19] of Number);
 
    function clone: colorMatrixFilter;
  end;
et voici comment l'utiliser
Code :
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
 
procedure Image.onKeyDown;
var i,j:integer;
    col:Number;
    R,V,B,moy:Number;
    filter: ColorMatrixFilter;
begin
(*
 For i:=0 to 520 do for j:=0 to 366 do
 begin
   col:=mybmp.GetPixel(i,j);
   R:=GetRValue(floor(col));
   V:=GetGValue(floor(col));
   B:=GetBValue(floor(col));
   moy:=Floor((R+V+B)/3);
   mybmp.SetPixel( i,j,RGB(moy,moy,moy) );
 end;
   mybmp.draw(mybmp);
 *)
 
// filtre matriciel
//  r' = 1/3 * r + 1/3 * g + 1/3 * b + 0 * a + 0
//  g' = 1/3 * r + 1/3 * g + 1/3 * b + 0 * a + 0
//  b' = 1/3 * r + 1/3 * g + 1/3 * b + 0 * a + 0
//  a' =   0 * r +   0 * g +   0 * b + 1 * a + 0
 filter := ColorMatrixFilter.Create([
  1/3,1/3,1/3, 0, 0,
  1/3,1/3,1/3, 0, 0,
  1/3,1/3,1/3, 0, 0,
    0,  0,  0, 1, 0
 ]);
 mybmp.applyFilter(mybmp, mybmp.rectangle, Point.Create(0, 0), filter);
end;
ça donne le même résultat que ton code...mais c'est quasiment instantané

EDIT: note que les modifications sont affichées sans qu'il soit nécessaire d'appeler draw()
__________________
Developpez.com: Mes articles, forum FlashPascal
Entreprise: Execute SARL
Produits : UPnP, RemoteOffice, FlashPascal
Embarcadero : Ile de la Réunion, Dephi, C++Builder, RADPHP...TVA à 8,5%
Paul TOTH est déconnecté   Envoyer un message privé Réponse avec citation 20
Vieux 19/06/2012, 15h58   #3
Archimède
Membre émérite
 
Avatar de Archimède
 
Homme anthony
Enseignant
Inscription : avril 2005
Messages : 1 026
Détails du profil
Informations personnelles :
Nom : Homme anthony
Localisation : France, Charente Maritime (Poitou Charente)

Informations professionnelles :
Activité : Enseignant
Secteur : Enseignement

Informations forums :
Inscription : avril 2005
Messages : 1 026
Points : 975
Points : 975
Oh génial...Je regarde ça de près

merci super

anthony
__________________
Citation:
tout développeur plongé dans son code subit une poussée d'urticaire de bas en haut égale au poids du volume d'unités qu'il ajoute.
Archimède est déconnecté   Envoyer un message privé Réponse avec citation 00
Réponse
Outils de la discussion

Navigation rapide


Fuseau horaire GMT +2. Il est actuellement 05h53.


 
 
 
 
Partenaires

Hébergement Web