Two big red flags I noticed in the source: the "WriteBitmapToPNGFile" and "ReadBitmapFromPNGFile" procedures in Tiles.pas. They simply won't work as written, in Lazarus. No matter what extension you provide the write procedure, it will always be saved as an actual bitmap (open something you've saved like this in IrfanView if you want to confirm, it will show a message alerting you about the wrong extension.) The read procedure will just straight-up raise an exception that says "Wrong image format." Here's refactored versions of both that work as intended for me:
Code:
procedure WriteBitmapToPNGFile (OutputFilename: string; Bitmap: TBitmap; TransparentColor: Integer);
var
APNG: TPortableNetworkGraphic;
begin
Bitmap.Transparent := True;
Bitmap.TransparentColor := TransparentColor;
APNG := TPortableNetworkGraphic.Create;
APNG.Assign(Bitmap);
Bitmap.Free;
APNG.SaveToFile(OutputFilename);
APNG.Free;
end;
procedure ReadBitmapFromPNGFile (InputFilename: string; Bitmap: TBitmap);
var
APNG: TPortableNetworkGraphic;
begin
APNG := TPortableNetworkGraphic.Create;
APNG.LoadFromFile(InputFileName);
Bitmap.Assign(APNG);
APNG.Free;
end;
Also, in the main form, the end of the SaveCurrentTile1Click procedure needs to be changed from this
Code:
if UpperCase(ExtractFileExt (SavePictureDialog.Filename)) = '.PNG' then
begin
bmpTemp.TransparentColor := TRANS_COLOR;
WriteBitmapToPngFile (SavePictureDialog.Filename, bmpTemp, TRANS_COLOR);
end
else
bmpTemp.SaveToFile (SavePictureDialog.FileName);
bmpTemp.Free;
to this:
Code:
if UpperCase(ExtractFileExt (SavePictureDialog.Filename)) = '.PNG' then
begin
bmpTemp.TransparentColor := TRANS_COLOR;
WriteBitmapToPngFile (SavePictureDialog.Filename, bmpTemp, TRANS_COLOR);
end
else
begin
bmpTemp.SaveToFile (SavePictureDialog.FileName);
bmpTemp.Free;
end;
Otherwise it will raise an access violation whenever you attempt to save to PNG (since the WriteBitmapToPNGFile procedure also frees the Bitmap.)
EDIT: Just noticed the WriteTileBitmap function called by TMainForm.Generate1Click has the same problem. The ending needs to be changed from this:
Code:
if Ext = '.PNG' then
WriteBitmapToPngFile(Filename, TempBitmap, TransColor)
else
TempBitmap.SaveToFile(FileName);
end;
TempBitmap.Free;
WriteTileBitmap := True;
to this:
Code:
if Ext = '.PNG' then
WriteBitmapToPngFile(Filename, TempBitmap, TransColor)
else
begin
TempBitmap.SaveToFile(FileName);
TempBitmap.Free;
end;
end;
WriteTileBitmap := True;
Bookmarks