Reputation: 37
My program loads a lot of images, but i have a problem with 1 image that used the print-screen button to copy it, from a game, however it is bmp, like all the rest. Whenever i run the program, it says project1.exe raised exception class Ereaderror with message 'stream read error' process stopped....
The code is this:
procedure TForm1.FormCreate(Sender: TObject);
var path, destination:string;
begin
path:=paramstr(0);
destination:=extractfilepath(path)+'Leagueoflegendsdesktop.bmp';
image1.Picture.LoadFromFile(destination);
end;
Which is correct. What do you suggest me?
Upvotes: 0
Views: 5952
Reputation: 612794
The only explanation is that the file is not a valid Windows bitmap (maybe the file is truncated). Or perhaps the file uses some esoteric format not supported by Delphi. Is it using run-length encoding, for example.
If the file did not exist you'd get a different error, one that indicated that no such file exists. So, the file exists but cannot be loaded. Ergo, it's not a Windows bitmap.
Step 1 to diagnose this is to look at the format of the file. Load up the bitmap file header and check that the values make sense. Probably the easiest way to do this is to step through the VCL code when running your program under the debugger. Enable the Debug DCUs option so that you can do that. Set a breakpoint in TBitmap.ReadStream
in the Graphics
unit and take it from there.
Having said all that, it may just be easier for you to avoid trying to debug the problem at all. If you can load the image into an image editor, simply save a new copy of the image in a format that will be read by Delphi. For example a plain vanilla Windows bitmap, or, even better, a PNG file which will admit compression.
Upvotes: 1