weixin_39671964
2020-12-05 13:43 阅读 1

Streamline ImageData:encode

Original report by Bill Meltsner (Bitbucket: bmelts, GitHub: bmelts).

Currently, to save an image from LÖVE, you need to use ImageData:encode(format) to produce an EncodedImageData, and then use love.filesystem to put it in a file. This is kind of kludgy, and having the separate EncodedImageData step doesn't make a lot of sense since there's really nothing else you can use it for.

Instead, change the method to ImageData:encode(path, format) or ImageData:encode(file, format), passing a string or a File, which encodes the ImageData to the specified format and writes it to the relevant location in one fell swoop. Bonus points for making format optional and autodetecting the proper format from the file extension in its absence.

(Hat tip to itsnotabigtruck for the idea.)

该提问来源于开源项目:love2d/love

  • 点赞
  • 写回答
  • 关注问题
  • 收藏
  • 复制链接分享

4条回答 默认 最新

  • weixin_39671964 weixin_39671964 2020-12-05 13:43

    Original comment by Bart van Strien (Bitbucket: bartbes, GitHub: bartbes).

    I applaud this.

    点赞 评论 复制链接分享
  • weixin_39671964 weixin_39671964 2020-12-05 13:43

    Original comment by Anonymous.

    Notice that there are some things to take into account, related with transparency:

    http://love2d.org/forums/viewtopic.php?f=4&t=2273

    点赞 评论 复制链接分享
  • weixin_39671964 weixin_39671964 2020-12-05 13:43

    Original comment by Boolsheet (Bitbucket: Boolsheet, GitHub: Boolsheet).

    Attaching a small patch as a suggestion. It changes the code to save the TGA with alpha channel.

    点赞 评论 复制链接分享
  • weixin_39671964 weixin_39671964 2020-12-05 13:43

    Original comment by Bart van Strien (Bitbucket: bartbes, GitHub: bartbes).

    Merged with another image saving ticket.

    Duplicate of #238.

    点赞 评论 复制链接分享

相关推荐