A strange problem. Maybe someone can give some idea.
Scenario 1 . I have a TBitmap in memory that is being written while complex calculations are being done to calculate the color of each pixel. Each time, so often (usually after each horizontal line filled with a bitmap), TBitmap refers to the image on the form (image1.Canvas.Draw (0, 0, TBitmap). In most cases this works fine, but I noticed that if for each line bitmap there are many slow complex calculations (say, to calculate more than 30 seconds or minutes), the main form has an instant "flicker", which somehow erases the bitmap, so the call image.draw only draws the last calculated line and the first y -strings grind in the bitmap.I circumvented this by locking the bitmap before calculations.
Scenario 2. This is the main problem. I am writing in a TMemoryStream, not a bitmap. The same deal. Calculations are performed to calculate the value of each pixel, and then each pixel value is written to TMemoryStream with memstream.Write (bytevalue, 1) during the process. At the end of all calculations, I save the stream to a bitmap with memstream.SaveToFile ('whatever.bmp'), and then frees the stream from memstream.Free. If the calculation is quick, the thread saves no matter what size (I do tests with dimensions of 10000x10000).
I can even say that the resulting file will be damaged, since the main window / application form of the application has a slight flicker, as if it were being repainted. When this happens, it is as if every bitmap descriptor and TMemoryStream has been killed / updated so that existing data is corrupted.
Any ideas? It really sucks. Especially when it may take an hour for each individual image to create just to find that a bitmap or TMemoryStream has happened and is corrupted when something has finished in the background.
- TMemoryStream, , ? . - , Delphi " , , "
- Delphi, .
TMemoryStream , , . , , , .
Windows 7, Vista.
1:
, , ...
( - )...
. memystream 5000x5000, , , cals .
SetupMemorystream;
for y:=0 to height do
for x:=0 to width do
DoCalcs;
SetByteValue;
end;
end;
SaveStream;
DoCalcs , . , TMemoryStream , , .
TBitmap , , , Delphi / Windows, " ", .
, , TMemoryStream .
2:
.
TMemoryStream OK, ( 5000x5000) 75 000 054 .
, ( , , ). - 22 9 .
, , , , - .
. , TMemoryStream SaveToFile ?