Welcome, Guest. Please login or register. Did you miss your activation email?

Author Topic: Loading PNG?  (Read 13019 times)

0 Members and 1 Guest are viewing this topic.

koskos

  • Newbie
  • *
  • Posts: 1
    • View Profile
Loading PNG?
« on: May 18, 2010, 04:21:45 am »
I've just been going through the tutorial and trying things out. I don't seem to be able to load PNG using Image.LoadFromFile()

When running:
Code: [Select]

  Image Image;
  if (!Image.LoadFromFile("./sprites2.png")) {
    std::cerr << "Could not load image" << std::endl;
    return -1;
  }


I get the message:
Quote
Failed to load image "./sprites2.png". Reason : PNG not supported: 8-bit only



The PNG is a simple one created using GIMP and it works in other viewers. Is there something else that I should be doing to load PNGs?

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32498
    • View Profile
    • SFML's website
    • Email
Loading PNG?
« Reply #1 on: May 18, 2010, 08:27:01 am »
The message is clear: don't use 8-bits PNG, save it as 24 or 32 bits.
Laurent Gomila - SFML developer

Ashenwraith

  • Sr. Member
  • ****
  • Posts: 270
    • View Profile
Loading PNG?
« Reply #2 on: May 19, 2010, 05:20:04 am »
I use 8-bit pngs made in photoshop and it works.

Of course SFML thinks it's a 32bit and I created my own code to manage palletes

Antidote

  • Newbie
  • *
  • Posts: 35
    • View Profile
Loading PNG?
« Reply #3 on: May 24, 2010, 03:24:36 am »
Actually the error message is kinda cryptic if you look at it.

Does it mean that only 8-bit png files are supported? Or is the image 8-bit only?

See what I'm getting at?

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32498
    • View Profile
    • SFML's website
    • Email
Loading PNG?
« Reply #4 on: May 24, 2010, 11:27:23 am »
The image is 8-bit, which is not supported.
Laurent Gomila - SFML developer

Kingdom of Fish

  • Jr. Member
  • **
  • Posts: 72
    • View Profile
Loading PNG?
« Reply #5 on: May 24, 2010, 12:46:31 pm »
I agree that the message is cryptic. But I really do believe that SFML should support all PNGs

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32498
    • View Profile
    • SFML's website
    • Email
Loading PNG?
« Reply #6 on: May 24, 2010, 12:58:54 pm »
SFML has nothing to do with the cryptic message or the lack of support for 8-bit PNGs, it just uses the SOIL library for loading images.
Laurent Gomila - SFML developer

Ashenwraith

  • Sr. Member
  • ****
  • Posts: 270
    • View Profile
Loading PNG?
« Reply #7 on: May 24, 2010, 10:53:22 pm »
Well 8-bit loading works because like I said I use them all the time.

The problem has to be different headers or packing--perhaps with how the pallete is set. For example, dds has a lot of different ways to load the same format.

Aesthete

  • Newbie
  • *
  • Posts: 3
    • View Profile
    • Matt Millwood
Loading PNG?
« Reply #8 on: June 26, 2010, 02:23:40 pm »
I had the same problem with some Menu Button sprites that were 48-bit.

I wasn't going to make them again so I just opened them in MS Paint, through the edit option and saved them again. Saves them as 32-bit.
A casual stroll through the lunatic asylum shows that faith does not prove anything.
 - Friedrich Nietzsche

asveron

  • Newbie
  • *
  • Posts: 2
    • View Profile
Loading PNG?
« Reply #9 on: October 20, 2011, 12:05:44 pm »
This is an outdated thread, but I just encountered the problem and would like to share my solution. Just in case somebody runs into the same problem.

Actually when it says "Failed to load image "IMAGE NAME". Reason : PNG not supported: 8-bit only" It actually meant it only accepts 8 bit.

The admin kept saying it doesn't accepts 8 bit, which confused a lot of people. But it's actually the opposite: it only accepts 8 bit. I don't know about 24 bits, but I think 16 and 32 does not work.

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32498
    • View Profile
    • SFML's website
    • Email
Loading PNG?
« Reply #10 on: October 20, 2011, 12:47:21 pm »
It depends if you refer to the size of a pixel, or the size of its components. I thought the message was referring to pixel size (so 8 bits is either gray-scale or palettized), but it's true that it could refer to component size, in which case 8 bits is the supported value.

But people who encounter this problem should know better if the image they try to load is 8-bits pixels or 8-bits components, and interpret the error message accordingly ;)
Laurent Gomila - SFML developer