Hello everybody!! My english is nt verygood, but I hope you can understand my.
I have a Library named LodePNG
http://members.gamedev.net/lode/projects/LodePNG/this library decodes a PNG-picture, and then I want lode it with the function LoadFromMemory().
My code looks like this:
FromFilePNG.hpp
#ifndef FROMFILEPNG_HPP_INCLUDED
#define FROMFILEPNG_HPP_INCLUDED
#include <SFML/Graphics.hpp>
#include ".\LodePNG\lodepng.h"
#include <iostream>
using namespace std;
class C_PNGFromFile
{
private://members for LoadPNG
vector<unsigned char>m_buffer, m_image;
private://members for GetPicturePNG
const char* m_image_c;
size_t m_size;
sf::Image m_Picture;
public://Public Member-Functions
bool LoadPNG();
sf::Image& GetPicturePNG();
};
#endif // FROMFILEPNG_HPP_INCLUDED
FromFilePNG.cpp
#include "FromFilePNG.hpp"
//Lode PNG with LodePNG and Decode
bool C_PNGFromFile::LoadPNG()
{
//Lode Image from png-File, and given filename
LodePNG::loadFile(m_buffer, "Images/Test5.png");
LodePNG::Decoder decoder;
//Decode the Image in 32bit
decoder.decode(m_image, m_buffer);
//stop if there is an error
if(decoder.hasError())
{
cout <<"error: "<<decoder.getError()<<endl;
return false;
}
return true;
}
//Loade the Picture with SFML and give it back
sf::Image& C_PNGFromFile::GetPicturePNG()
{
if(m_image.size() > 0)
{
//Cast from "vector<unsigned char>" to "const char*"
m_image_c = reinterpret_cast<const char*>(&m_image[0]);
//Get size in Byte's
m_size = m_image.size();
}
cout<<"Size: "<<m_size<<endl;
//Lode File from Memory with SFML, and check
if(false == m_Picture.LoadFromMemory(m_image_c, m_size));
{
cout<<"Error: Picture cant by loadet."<<endl;
}
//return the Image
return m_Picture;
}
I dont know whats going wrong here
In the Shell-Window, I can read:
Size: 1228800
Failed to load image from memory. Reason : Image not of any known type, or corrupt
Error: Picture cant by loadet.
Has anyone an idea, whats going wrong?