Mesen-X/Utilities/PNGWriter.h
2014-07-10 21:17:37 -04:00

25 lines
No EOL
678 B
C++

#pragma once
#include "stdafx.h"
#include "miniz.h"
using std::ofstream;
class PNGWriter
{
public:
static bool WritePNG(wstring filename, uint8_t* buffer, uint32_t xSize, uint32_t ySize, uint32_t bitsPerPixel = 32)
{
size_t pngSize = 0;
void *pngData = tdefl_write_image_to_png_file_in_memory_ex(buffer, xSize, ySize, bitsPerPixel/8, &pngSize, MZ_DEFAULT_LEVEL, MZ_FALSE);
if(!pngData) {
std::cout << "tdefl_write_image_to_png_file_in_memory_ex() failed!" << std::endl;
return false;
} else {
ofstream file(filename, ios::out | ios::binary);
file.write((char*)pngData, pngSize);
file.close();
mz_free(pngData);
return true;
}
}
};