Funktion um ein 2D ByteArray in ein 1D ByteArray zu konvertieren:
Delphi-Quellcode:
type
TArray2D = Array of Array of Byte;
TArray1D = Array of Byte;
function Array2DTo1D(AArray: TArray2D): TArray1D;
var y,x: Integer;
n: Integer;
begin
SetLength(Result, Length(AArray) * Length(AArray[0]));
n := 0;
for y := 0 to High(AArray) do
begin
for x := 0 to High(AArray[y]) do
begin
Result[n] := AArray[y,x];
inc(n);
end;
end;
end;
Test:
Delphi-Quellcode:
procedure TForm1.FormCreate(Sender: TObject);
var arr2: TArray2D;
arr1: TArray1D;
y,x: Integer;
begin
// Arr2 mit Testdaten befüllen
SetLength(arr2, 3, 3);
for y := 0 to High(arr2) do
for x := 0 to High(arr2[y]) do
arr2[y,x] := random(100);
// arr2 in 1D Array konvertieren
arr1 := Array2DTo1D(arr2);
end;
Am Ende der Testmethode sehen die Arrays aus wie im Anhang
Michael
"Programmers talk about software development on weekends, vacations, and over meals not because they lack imagination,
but because their imagination reveals worlds that others cannot see."