SFML community forums
Help => Graphics => Topic started by: Lemon on January 15, 2010, 07:23:36 pm
-
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?
-
Try to save your PNG to a file and open it with an image viewer, to see if it's valid or not.
And why do you use your own code to load PNG file?
-
thx for answer!
And why do you use your own code to load PNG file?
I heart it gives a Function in SFML to loade Pictures binary but the point is I whant make an editor for my game. And I loade the PNG in the editor and save it there binary to loade it again with the game.
I fixed the bug!
//Lode PNG with LodePNG and Decode
bool C_PNGFromFile::LoadPNG()
{
//Lode Image from png-File, and given filename
LodePNG::loadFile(m_buffer, "Images/Test3.png");
}
//Loade the Picture with SFML and give it back
sf::Image& C_PNGFromFile::GetPicturePNG()
{
if(m_buffer.size() > 0)
{
//Cast from "vector<unsigned char>" to "const char*"
m_image_c = reinterpret_cast<const char*>(&m_buffer[0]);
//Get size in Byte's
m_size = m_buffer.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 have to decode. I dont now wath really is decode. But it works.
I have a question. By some pictures it dont works. The Error is:
Failed to image font from memory, Reason : PNG not supported: 8-bit only
why this?
EDIT:
The picture there not goes is 48bit. But a picture with 24bit goes.
The error must look like this:
Failed to image font from memory, Reason : PNG not supported: 8-bit only but 24-bit too ;)
-
Something going wrong here!!
my code:
//Lode File from Memory with SFML, and check
if(false == m_Picture.LoadFromMemory(m_image_c, m_size));
{
cout<<"FromFilePNG/ Error: Picture cant by loadet."<<endl;
}
the false here by the "if-question" can bi false or true, is equal, it coms everitime the "cout":
FromFilePNG/ Error: Picture cant by loadet.
I can load the Picture!!
In the docu is writed, if the return is false, the picture cant by loaded.
I think ther is a Bug in SFML!!
Sorry for the aspect but it is really strange.
-
Ehhh, I feel like a grammar nazi for going over every mistake in my head.(Grammar nazi is a joke term, don't take it seriously).
Yeah, I can't really understand much, but it sounds like you are getting errors with 48-bit images? This would make sense, since 48-bit images aren't supported by any graphics card/monitor afaik. And there's really no point to have any higher quality than 24-bit, as 24-bit is the most the human eye can see.
-
yes have it realized the error. I not really want take 48bit Pictures in my Game. But first I have not seen that the Picture is 48bit and the error tangle my.