mirror of
https://github.com/love2d/love.git
synced 2026-08-17 11:00:31 +02:00
Added a variant of love.graphics.captureScreenshot which takes a single filename parameter. Resolves issue #1293.
--HG-- branch : minor
This commit is contained in:
@@ -22,6 +22,8 @@
|
||||
#include "ImageData.h"
|
||||
#include "Image.h"
|
||||
|
||||
#include "filesystem/Filesystem.h"
|
||||
|
||||
namespace love
|
||||
{
|
||||
namespace image
|
||||
@@ -154,7 +156,7 @@ void ImageData::decode(love::filesystem::FileData *data)
|
||||
decodeHandler = decoder;
|
||||
}
|
||||
|
||||
love::filesystem::FileData *ImageData::encode(EncodedFormat encodedFormat, const char *filename)
|
||||
love::filesystem::FileData *ImageData::encode(EncodedFormat encodedFormat, const char *filename, bool writefile)
|
||||
{
|
||||
FormatHandler *encoder = nullptr;
|
||||
FormatHandler::EncodedImage encodedimage;
|
||||
@@ -208,6 +210,27 @@ love::filesystem::FileData *ImageData::encode(EncodedFormat encodedFormat, const
|
||||
memcpy(filedata->getData(), encodedimage.data, encodedimage.size);
|
||||
encoder->free(encodedimage.data);
|
||||
|
||||
if (writefile)
|
||||
{
|
||||
auto fs = Module::getInstance<filesystem::Filesystem>(Module::M_FILESYSTEM);
|
||||
|
||||
if (fs == nullptr)
|
||||
{
|
||||
filedata->release();
|
||||
throw love::Exception("love.filesystem must be loaded in order to write an encoded ImageData to a file.");
|
||||
}
|
||||
|
||||
try
|
||||
{
|
||||
fs->write(filename, filedata->getData(), filedata->getSize());
|
||||
}
|
||||
catch (love::Exception &)
|
||||
{
|
||||
filedata->release();
|
||||
throw;
|
||||
}
|
||||
}
|
||||
|
||||
return filedata;
|
||||
}
|
||||
|
||||
|
||||
@@ -47,7 +47,7 @@ public:
|
||||
|
||||
// Implements image::ImageData.
|
||||
virtual love::image::ImageData *clone() const;
|
||||
virtual love::filesystem::FileData *encode(EncodedFormat encodedFormat, const char *filename);
|
||||
virtual love::filesystem::FileData *encode(EncodedFormat encodedFormat, const char *filename, bool writefile);
|
||||
|
||||
private:
|
||||
|
||||
|
||||
Reference in New Issue
Block a user