Results 1 to 10 of 40

Thread: TileStudio for Lazarus

Threaded View

Previous Post Previous Post   Next Post Next Post
  1. #31
    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;
    Last edited by Akira13; 20-03-2017 at 01:32 AM.

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •