savePNG method for Image

master
Sam 10 years ago
parent 455000c02d
commit 67c2453c82

@ -24,6 +24,7 @@
#include "image.h"
#include <framework/core/resourcemanager.h>
#include <framework/core/filestream.h>
#include <framework/graphics/apngloader.h>
Image::Image(const Size& size, int bpp, uint8 *pixels)
@ -62,6 +63,20 @@ ImagePtr Image::loadPNG(const std::string& file)
return image;
}
void Image::savePNG(const std::string& fileName)
{
FileStreamPtr fin = g_resources.createFile(fileName);
if(!fin)
stdext::throw_exception(stdext::format("failed to open file '%s' for write", fileName));
fin->cache();
std::stringstream data;
save_png(data, m_size.width(), m_size.height(), 4, (unsigned char*)getPixelData());
fin->write(data.str().c_str(), data.str().length());
fin->flush();
fin->close();
}
void Image::overwriteMask(const Color& maskedColor, const Color& insideColor, const Color& outsideColor)
{
assert(m_bpp == 4);
@ -252,4 +267,4 @@ void Texture::generateSoftwareMipmaps(std::vector<uint8> inPixels)
setupFilters();
}
}
*/
*/

@ -34,6 +34,8 @@ public:
static ImagePtr load(std::string file);
static ImagePtr loadPNG(const std::string& file);
void savePNG(const std::string& fileName);
void overwriteMask(const Color& maskedColor, const Color& insideColor = Color::white, const Color& outsideColor = Color::alpha);
void blit(const Point& dest, const ImagePtr& other);
void paste(const ImagePtr& other);

Loading…
Cancel
Save