Bonjour,

j'ai un Bitmap Bmp1 (320 x 320 pixels) et un Bitmap Bmp2 (32 x 32 pixels). Je cherche à copier un pixel sur 10 de Bmp1 vers Bmp2.

J'ai une violation d'accès dans ce code lorsque y = 0, i = 0, x = 110, i = 11 :

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
Const
  PixelCountMax = 32768;
 
Type
  pRGBTripleArray = ^TRGBTripleArray;
  TRGBTripleArray = ARRAY[0..PixelCountMax-1] OF TRGBTriple;
...
 
procedure TF_Princ.FormCreate(Sender: TObject);
begin
  Bmp1 := TBitMap.Create ;
  Bmp1.width := 320 ;
  Bmp1.Height := 320 ;
  Bmp1.PixelFormat := pf24bit;
  Bmp2 := TBitMap.Create ;
  Bmp2.width := 32 ;
  Bmp2.Height := 32 ;
  Bmp2.PixelFormat := pf24bit;
end;
...
 
Procedure TF_Princ.Copier ;
Var
  x, y    : Integer;
  i, j    : Integer ;
  P1, P2  : pRGBTripleArray ;     // PByteArray;
Begin
    j := 0 ;
    y := 0 ;
    While y <= (Bmp1.Height -1) do
      Begin
        x := 0 ;
        i := 0 ;
        Label1.Caption := Format('y : %d  j : %d  x : %d  i  : %d',[y, j, x, i]) ;
        Application.ProcessMessages ;
        P1 := Bmp1.ScanLine[y];
        P2 := Bmp2.ScanLine[j];
        While x <= (Bmp1.Width -1) do
          Begin
            P2[i] := P1[x] ;
            Inc(i) ;
            Inc(x,10) ;
        Label1.Caption := Format('y : %d  j : %d  x : %d  i  : %d',[y, j, x, i]) ;
        Application.ProcessMessages ;
          End;
        Inc(j) ;
        Inc(y,10) ;
      End;
    Image2.Picture.Bitmap.Assign(Bmp2);
End ;
Je ne comprends pas pourquoi ?

avec au lieu de
Code : Sélectionner tout - Visualiser dans une fenêtre à part
 P1, P2  : pRGBTripleArray ;
je n'ai pas de violation, mais le résultat dans image2 ne prend que 25% de l'image en largeur ?

Avez vous une idée ?

Merci
A+
Charly