Bonsoir,

J'ai récupéré sur la page https://forum.lazarus.freepascal.org...html#msg269273 une procédure "stand-alone" dont la partie centrale me joue des tours et me fait des misères.
Au départ ça ressemble à ça :
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
    Intf:=CY.CreateIntfImage;
    for i:=0 to pred(CY.Width) do
      for j:=0 to pred(CY.Height) do
        if Intf.TColors[i,j] > 0 then 
          Intf.TColors[i,j] := Intf.TColors[i,j] or $FF000000; // --> RangeCheckError
et pour essayer de comprendre, j'ai bricolé les deux dernières lignes ci-dessus comme ça :
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
        if Intf.TColors[i,j] > 0 then begin
        //Intf.TColors[i,j] := Intf.TColors[i,j] or $FF000000; // --> RangeCheckError
          total := Intf.TColors[i,j] or $FF000000;
          if total > 4294967294 then
            mmo.append(inttostr(Intf.TColors[i,j])+'  i='+inttostr(i)+'  j='+inttostr(j)+'  total='+inttostr(total));
          Intf.TColors[i,j] := total; // --> RangeCheckError
        end;
Donc ma bidouille n'a rien changé, sauf que, pour la construire, cette bidouille, j'y suis allé petit à petit à coups d'ajouts de données dans le mémo, avec des begin end, de l'Application.ProcessMessages, l'introduction d'une variable intermédiaire bref j'ai réussi à faire fonctionner le bazar !
Mais il aura suffi que j'enlève les tests et autres trucs inutiles (conservation de la variable intermédiaire) pour que ça ne fonctionne plus...

Le gag c'est que si je commente la dernière ligne, je n'ai plus d'erreur et j'ai une image !, mon seul souci étant que je ne sais pas du tout si cette image que je vois est celle que je dois voir, ne comprenant pas trop à quoi sert la boucle for i for j.

C'est pourquoi je compte un peu sur vous, avec les uses qui vont bien (y en a surement de trop) et le code de la procédure (qui aura besoin d'un TMemo name mmo) :
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
uses
  LclType, GraphType, LCLIntf,
  Classes, SysUtils, Forms, Controls, Graphics, Dialogs,
  FPWritePNG, FPWriteBMP, FPReadPNG, FPReadBMP,
  IntfGraphics, FPImage, FPCanvas, ExtDlgs, StdCtrls;
 
procedure TForm1.Button1Click(Sender: TObject);
var
  CY: TPortableNetworkGraphic;
  i, j: Integer;
  Intf: TLazIntfImage;
  total: uint;
begin
  CY := TPortableNetworkGraphic.Create;
  CY.PixelFormat := pf32bit;
  CY.Canvas.Brush.FPColor:=colTransparent;
  CY.SetSize(300,300);
  CY.Canvas.FillRect(0,0,CY.Width-1,CY.Height-1);
  try
    CY.Canvas.Brush.Style := bsClear;
    CY.Canvas.Pen.FPColor := ColRed;
    CY.Canvas.Pen.Width := 10;
    CY.Canvas.Ellipse(10,10,100,100);
    with CY.Canvas.Font do begin
        FPColor := ColLime;
        PixelsPerInch := 300; /// always before height!
        Height := 32;
        ///Orientation := 1800;  /// Text is drawn upside down from right to left.
        Orientation := 0;  /// Text is drawn horizontally from left to right.
        Name := 'PlayBill';
        Quality := fqCleartypeNatural;
    end;
 
    CY.Canvas.Brush.Style := bsImage;
//  CY.Canvas.TextOut(230,230,'EDGAR RULES!'); // if orientation = 1800
    CY.Canvas.TextOut(23,230,'EDGAR RULES!');  // if orientation = 0
 
    /// The plain bitmap has no Alpha, so we have to create an IntfImage, which passes the
    /// actual Canvas into an ABGR format that we control with TColors property.  After putting
    /// to all the painted things the $FF on the Alpha position, we pass it back to the CY.Canvas
 
    Intf:=CY.CreateIntfImage;
    for i:=0 to pred(CY.Width) do
      for j:=0 to pred(CY.Height) do
        if Intf.TColors[i,j] > 0 then begin
        //Intf.TColors[i,j] := Intf.TColors[i,j] or $FF000000; // --> RangeCheckError
          total := Intf.TColors[i,j] or $FF000000;
          if total > 4294967295 then
            mmo.append(inttostr(Intf.TColors[i,j])+'  i='+inttostr(i)+'  j='+inttostr(j)+'  tot='+inttostr(total));
{          Intf.TColors[i,j] := total-1; // --> RangeCheckError  }
        end;                   // ce -1 ne change rien
    CY.LoadFromIntfImage(Intf);
 
    // scories de calcul
    // cardinal max = 4294967295
    //    $FF000000 = 4278190080
    //   4294967295
    // - 4278190080
    // =   16777215
 
    Canvas.Draw(50,50,CY); // dessine sur la fiche.
    CY.SaveToFile('./pruebaPNG.png');
  finally
    CY.Free;
    Intf.Free;
  end;
end;
Merci d'avance (il y a des noms bizarres dans ce code, ça ne gêne en rien)
Nom : pruebaPNG.png
Affichages : 156
Taille : 3,5 Ko,