Results 1 to 10 of 40

Thread: TileStudio for Lazarus

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Quote Originally Posted by Wiering View Post

    Bitmap transparency doesn't seem to work properly in Lazarus (or very different from Delphi at least). At first I thought it didn't work at all (posted an issue here
    http://bugs.freepascal.org/view.php?id=31556 ), but now I see that it does work if you set up the transparent color first. However, once you draw the bitmap onto something else, it forgets its transparent color, but somehow does keep a mask of the transparency you had before. In Delphi, you can just set the transparent color at any time and it will draw the image accordingly.

    (...)

    [Edit] I found a workaround by adding Bitmap.Mask() before every Draw, which is probably very inefficient, but now the maps are rendered correctly.
    That may explain the erratic behaviour I had. Some times it works, some times it doesn't...
    No signature provided yet.

  2. #2
    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
  •