Delphi-PRAXiS
Seite 1 von 2  1 2      

Delphi-PRAXiS (https://www.delphipraxis.net/forum.php)
-   Multimedia (https://www.delphipraxis.net/16-multimedia/)
-   -   Fehler bei Bereichsprüfung für ein bitmap drehen (https://www.delphipraxis.net/199875-fehler-bei-bereichspruefung-fuer-ein-bitmap-drehen.html)

zeina 27. Feb 2019 10:55


Fehler bei Bereichsprüfung für ein bitmap drehen
 
Hallo,
ich habe ein Problem und zwar,dass mein programm ein fehler Meldung (Fehler bei Bereichsprüfung)ausliefert.

Delphi-Quellcode:
type TRGBarray = array[0..0] of TRGBQuad;


procedure TFormFoto.rotate90(const Source:TGraphic ; Bmp: TBitmap);
var   P   : PRGBQuad;
  y, x, h, b: integer;
  Rowout   : ^TRGBarray;
  sourcebmp : TBitmap;
begin
  sourcebmp := TBitmap.Create;
  try
    sourcebmp.PixelFormat := pf32bit;
    sourcebmp.Height := Source.Height;
    sourcebmp.Width := Source.Width;
    sourcebmp.Canvas.Draw(0, 0, Source);
    Bmp.PixelFormat := pf32bit;
    b := sourcebmp.Height;
    h := sourcebmp.Width;
    Bmp.Height     := h;
    Bmp.Width      := b;
    for y := 0 to (h - 1) do begin
      rowout := Bmp.ScanLine[y];
      p := sourcebmp.ScanLine[sourcebmp.height-1];
      inc(p, y);
      for x := 0 to (b-1) do begin
      rowout[x] := p^;
      inc(p, h);
    end;
    end;
  finally
    sourcebmp.Free;
  end;
end;

sakura 27. Feb 2019 11:03

AW: Fehler bei Bereichsprüfung für ein bitmap drehen
 
Zitat:

Zitat von zeina (Beitrag 1426516)
ich habe ein Problem und zwar,dass mein programm ein fehler Meldung (Fehler bei Bereichsprüfung)ausliefert.

Hast Du im Debugger mal getestet, in welcher Zeile der Fehler auftritt?

...:cat:...

peterbelow 27. Feb 2019 11:08

AW: Bereichsüberlauf bei rin bitmap drehen
 
Zitat:

Zitat von zeina (Beitrag 1426516)
Hallo,
ich habe ein Problem und zwar,dass mein programm ein fehler Meldung (Bereichsüberlauf )ausliefert.

Das liegt daran, dass

Delphi-Quellcode:
type TRGBarray = array[0..0] of TRGBQuad;
definiert ist und Du dann später hemmunglos einen Index > 0 verwendest:

Delphi-Quellcode:

procedure TFormFoto.rotate90(const Source:TGraphic ; Bmp: TBitmap);
var   P   : PRGBQuad;
  y, x, h, b: integer;
  Rowout   : ^TRGBarray;
  sourcebmp : TBitmap;
begin
  ....
      rowout[x] := p^;

end;
Entweder Du schaltets die Bereichsüberprüfung für diese Methode aus ({$R-}) oder deklarierst den Typ z. B. als

Delphi-Quellcode:
type TRGBarray = array[0..(High(Cardinal) div Sizeof(TRGBQuad))-1] of TRGBQuad;
Mit dieser Deklaration darfst Du aber auf keinen Fall eine Variable dieses Typs deklarieren, die würde 4 GByte Speicher belegen! Mti einem Pointer darauf zu arbeiten ist aber kein Problem.

zeina 27. Feb 2019 11:19

AW: Fehler bei Bereichsprüfung für ein bitmap drehen
 
Zitat:

Zitat von sakura (Beitrag 1426517)
Zitat:

Zitat von zeina (Beitrag 1426516)
ich habe ein Problem und zwar,dass mein programm ein fehler Meldung (Fehler bei Bereichsprüfung)ausliefert.

Hast Du im Debugger mal getestet, in welcher Zeile der Fehler auftritt?

...:cat:...

Danke Für die Antwort:

mein Fehler triit in dieser Zeile auf:

Delphi-Quellcode:
     rowout[x] := p^;

zeina 27. Feb 2019 11:22

AW: Bereichsüberlauf bei rin bitmap drehen
 
Zitat:

Zitat von peterbelow (Beitrag 1426518)
Zitat:

Zitat von zeina (Beitrag 1426516)
Hallo,
ich habe ein Problem und zwar,dass mein programm ein fehler Meldung (Bereichsüberlauf )ausliefert.

Das liegt daran, dass

Delphi-Quellcode:
type TRGBarray = array[0..0] of TRGBQuad;
definiert ist und Du dann später hemmunglos einen Index > 0 verwendest:

Delphi-Quellcode:

procedure TFormFoto.rotate90(const Source:TGraphic ; Bmp: TBitmap);
var   P   : PRGBQuad;
  y, x, h, b: integer;
  Rowout   : ^TRGBarray;
  sourcebmp : TBitmap;
begin
  ....
      rowout[x] := p^;

end;
Entweder Du schaltets die Bereichsüberprüfung für diese Methode aus ({$R-}) oder deklarierst den Typ z. B. als

Delphi-Quellcode:
type TRGBarray = array[0..(High(Cardinal) div Sizeof(TRGBQuad))-1] of TRGBQuad;
Mit dieser Deklaration darfst Du aber auf keinen Fall eine Variable dieses Typs deklarieren, die würde 4 GByte Speicher belegen! Mti einem Pointer darauf zu arbeiten ist aber kein Problem.


Danke für die Antwort.
ich habe vorher es versucht :
Delphi-Quellcode:
type TRGBarray = array[0..(High(Cardinal) div Sizeof(TRGBQuad))-1] of TRGBQuad;
aber es tritt ein Fehler auf: E2100 Datentyp zu groß:2 GB überschritten:(

sakura 27. Feb 2019 11:59

AW: Bereichsüberlauf bei rin bitmap drehen
 
Zitat:

Zitat von zeina (Beitrag 1426522)
ich habe vorher es versucht :
Delphi-Quellcode:
type TRGBarray = array[0..(High(Cardinal) div Sizeof(TRGBQuad))-1] of TRGBQuad;
aber es tritt ein Fehler auf: E2100 Datentyp zu groß:2 GB überschritten:(

Versuche einfach mal:
Delphi-Quellcode:
type TRGBarray = array of TRGBQuad;
...:cat:...

Blup 27. Feb 2019 12:05

AW: Bereichsüberlauf bei rin bitmap drehen
 
Zitat:

Zitat von sakura (Beitrag 1426523)
Zitat:

Zitat von zeina (Beitrag 1426522)
ich habe vorher es versucht :
Delphi-Quellcode:
type TRGBarray = array[0..(High(Cardinal) div Sizeof(TRGBQuad))-1] of TRGBQuad;
aber es tritt ein Fehler auf: E2100 Datentyp zu groß:2 GB überschritten:(

Versuche einfach mal:
Delphi-Quellcode:
type TRGBarray = array of TRGBQuad;
...:cat:...

Das währe ein dynamisches Array und das geht in diesem Fall garnicht.

sakura 27. Feb 2019 12:39

AW: Bereichsüberlauf bei rin bitmap drehen
 
Zitat:

Zitat von Blup (Beitrag 1426525)
Das währe ein dynamisches Array und das geht in diesem Fall garnicht.

Stimmt :wall:
Aber das geht:
Delphi-Quellcode:
procedure Rotate90(const aSource:TGraphic; const aBmp: TBitmap);
var
  SourceBmp : TBitmap;
  SourcePixel, DestPixel: PRGBQuad;
  Y, X, SourceWidth, SourceHeight: Integer;
begin
  SourceBmp := TBitmap.Create;
  try
    SourceBmp.PixelFormat := pf32bit;
    SourceBmp.Height := aSource.Height;
    SourceBmp.Width := aSource.Width;
    SourceBmp.Canvas.Draw(0, 0, aSource);
    SourceHeight := SourceBmp.Height;
    SourceWidth := SourceBmp.Width;

    aBmp.PixelFormat := pf32bit;
    aBmp.Height := SourceWidth;
    aBmp.Width := SourceHeight;

    for Y := 0 to SourceWidth - 1 do
    begin
      DestPixel := aBmp.ScanLine[Y];
      SourcePixel := SourceBmp.ScanLine[SourceBmp.Height - 1];
      Inc(SourcePixel, Y);

      for X := 0 to SourceHeight - 1 do
      begin
        DestPixel^ := SourcePixel^;
        Inc(SourcePixel, SourceWidth);
        Inc(DestPixel);
      end;
    end;
  finally
    SourceBmp.Free;
  end;
end;
...:cat:...

Blup 27. Feb 2019 13:00

AW: Fehler bei Bereichsprüfung für ein bitmap drehen
 
Delphi-Quellcode:
  ...
  Inc(SourcePixel, SourceWidth);
Es wird von Annahmen ausgegangen, die nicht unbedingt so sein müssen:
- jede Zeile belegt nur so viel Speicher, wie für die Pixel unbedingt erforderlich ist
- die Zeilen liegen in absteigender Reihenfolge im Speicher

zeina 27. Feb 2019 13:16

AW: Bereichsüberlauf bei rin bitmap drehen
 
Zitat:

Zitat von sakura (Beitrag 1426526)
Zitat:

Zitat von Blup (Beitrag 1426525)
Das währe ein dynamisches Array und das geht in diesem Fall garnicht.

Stimmt :wall:
Aber das geht:
Delphi-Quellcode:
procedure Rotate90(const aSource:TGraphic; const aBmp: TBitmap);
var
  SourceBmp : TBitmap;
  SourcePixel, DestPixel: PRGBQuad;
  Y, X, SourceWidth, SourceHeight: Integer;
begin
  SourceBmp := TBitmap.Create;
  try
    SourceBmp.PixelFormat := pf32bit;
    SourceBmp.Height := aSource.Height;
    SourceBmp.Width := aSource.Width;
    SourceBmp.Canvas.Draw(0, 0, aSource);
    SourceHeight := SourceBmp.Height;
    SourceWidth := SourceBmp.Width;

    aBmp.PixelFormat := pf32bit;
    aBmp.Height := SourceWidth;
    aBmp.Width := SourceHeight;

    for Y := 0 to SourceWidth - 1 do
    begin
      DestPixel := aBmp.ScanLine[Y];
      SourcePixel := SourceBmp.ScanLine[SourceBmp.Height - 1];
      Inc(SourcePixel, Y);

      for X := 0 to SourceHeight - 1 do
      begin
        DestPixel^ := SourcePixel^;
        Inc(SourcePixel, SourceWidth);
        Inc(DestPixel);
      end;
    end;
  finally
    SourceBmp.Free;
  end;
end;
...:cat:...

prima...Das funktioniert...Danke:thumb:


Alle Zeitangaben in WEZ +1. Es ist jetzt 15:19 Uhr.
Seite 1 von 2  1 2      

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
LinkBacks Enabled by vBSEO © 2011, Crawlability, Inc.
Delphi-PRAXiS (c) 2002 - 2023 by Daniel R. Wolf, 2024 by Thomas Breitkreuz