Contains simple functions to load images. It is just a header/source file, so just a drag and drop is required. All code is within the namespace li
.
li::error error;
li::image_data data{li::load("cheese.png", &error)};
if(!data)
{
std::cerr << "Failed to load image\n";
std::cerr << "Reason:\n";
std::cerr << error << '\n';
}
// ... do something with the image
This library requires stb_image.
This library has taken some source code from the SFML library, however, I have altered it a little bit. Here are the differences:
- SFML copies the data returned from
stb_image
, and stores it within avector
. I simply "move" the data, with the use of aunique_ptr
(I basically copy the pointer to the data thatstb_image
returns). - I return the image data, instead of allowing it to be passed by reference. As it is a more C++11 approach.
- Since
std::unique_ptr
is used, memory is managed for you, but if you want to transfer ownership (that is, you want to manage the memory), then you can simply callrelease()
. Thus the RAII pattern is used to it's fullest.
See LICENSE