示例#1
0
文件: BitmapIO.cpp 项目: Virolea/gosu
void Gosu::saveImageFile(const Gosu::Bitmap& bitmap, Gosu::Writer writer,
    const std::wstring& formatHint)
{
    unsigned char* rgba =
        const_cast<unsigned char*>(reinterpret_cast<const unsigned char*>(bitmap.data()));
    
    // TODO: Use the new *_to_func functions in stb_imagewrite.h instead:
    // https://github.com/nothings/stb/blob/master/stb_image_write.h#L39
    int length;
    unsigned char* png =
        stbi_write_png_to_mem(rgba, 0, bitmap.width(), bitmap.height(), 4, &length);
    
    if (png == 0)
        throw std::runtime_error("Could not save image data to memory");
    
    try
    {
        writer.write(png, length);
    }
    catch (...)
    {
        STBIW_FREE(png);
        throw;
    }
    
    STBIW_FREE(png);
}
示例#2
0
文件: BitmapIO.cpp 项目: johan--/gosu
void Gosu::saveImageFile(const Gosu::Bitmap& bitmap, Gosu::Writer writer,
    const std::wstring& formatHint)
{
    unsigned char* rgba =
        const_cast<unsigned char*>(reinterpret_cast<const unsigned char*>(bitmap.data()));
    
    int length;
    unsigned char* png =
        stbi_write_png_to_mem(rgba, 0, bitmap.width(), bitmap.height(), 4, &length);
    
    if (png == 0)
        throw std::runtime_error("Could not save image data to memory");
    
    try
    {
        writer.write(png, length);
    }
    catch (...)
    {
        STBIW_FREE(png);
        throw;
    }
    
    STBIW_FREE(png);
}