I load an external bitmap file.
MyBitmap := tBitmap.Create;
MyBitmap.LoadFromFile(FileName);
This works. I also show it on the screen:
Form1.Image1.Picture.Bitmap := MyBitmap;
If I want to change pixels in it, that also works reasonably fast (I read all the acceleration methods, but for the time being it is fast enough for me if I use BeginUpdate/EndUpdate):
Form1.Image1.Picture.Bitmap.BeginUpdate(true);
for x := 0 to W - 1 do
for y := 0 to H - 1 do
Form1.Image1.Picture.Bitmap.Canvas.Pixels[x, y] := random($ff);
Form1.Image1.Picture.Bitmap.EndUpdate(false);
However if I want to read the same data, it gets extremely slow. I would expect that reading data should be much faster as less range checking, etc. might be needed, but it is the opposite.
Form1.Image1.Picture.Bitmap.BeginUpdate(true);
for x := 0 to W - 1 do
for y := 0 to H - 1 do
MyArray[x, y] := Form1.Image1.Picture.Bitmap.Canvas.Pixels[x, y];
Form1.Image1.Picture.Bitmap.EndUpdate(false);
I also tried to read it from the original bitmap, rather than the image, but it is the same speed:
MyBitmap.BeginUpdate(true);
for x := 0 to W - 1 do
for y := 0 to H - 1 do
MyArray[x, y] := MyBitmap.Canvas.Pixels[x, y];
MyBitmap.EndUpdate(false);
How could I make the read as fast as the write? I do not need faster than that, but currently it is like 50-100 times slower.