Reputation: 21
I'm using dynamic arrays for storing the keys, the pixels, and encrypted pixels. The program runs smoothly during the first encryption, but when changing the picture, the program crashes 'Access violation at adress 00401BF1 in module 'Project2.exe'. Write of address 00000001'.
I think it's because the setLength
procedure that i put inside the load picture button. This is the code i used after loading the picture. Note : there is also code for true color picture that i need to set the length 3 times bigger setLength(image1.picture.height * image1.picture.width * 3)
. But here's the simple one for grayscale picture in the load-picture button
SetLength(ppixels, image1.picture.height * image1.picture.width);
k := 0;
for i := 0 to Image1.picture.height-1 do
begin
PC := Image1.Picture.Bitmap.ScanLine[i];
for j := 0 to Image1.picture.width-1 do
begin
ppixels[k] := PC[j];
k := k + 1;
end;
end;
I tried to manipulate it with
if(Length(ppixels)<0) then setLength(ppixels, image1.picture.height * image1.picture.width);
That's work only for picture that have lesser pixel and that's not the soluton that i'm looking for. Also tried to set the length to be really big, like setLength(ppixels,100000000);
but it's gave me error 'Out of Memory'. Also have tried setLength(ppixels,0)
, ppixels := nil
, and Finalize(ppixels)
but thats didn't solve the problem and give error still.
Help me to solve this problem, Master. Thank you so much ~
Upvotes: 1
Views: 129
Reputation: 21
i don't know how to set the length dynamicly, my current best solution is to make it have big static size which is 75mil. so the program can only encrypt picture that have less than 75m pixels (5000 x 5000 px for colored picture). Please add answer for any suggest or solution, thank you !
Upvotes: 1