SFML community forums
Help => Graphics => Topic started by: Alia5 on May 25, 2011, 09:22:46 pm
-
hi
i need help to convert a qimage to an sf::image...
i just cant get it to work...
yeah, i can read and set every pixel, but you cant read the alpha of an pixel from an qimage :O
-
You must convert the image to ARGB32 (QImage::convertToFormat), get the pixels (QImage::bits), and play with bitwise operators to convert from ARGB to RGBA.
-
Take a look at here :
http://doc.qt.nokia.com/latest/qglwidget.html#convertToGLFormat
So, maybe something like this...
QImage source;
...
QImage converted = QGLWidget::convertToGLFormat(source);
sf::Image final;
final.LoadFromPixels(source.width(), source.height(), reinterpret_cast<const sf::Uint8*>(converted.bits()));
-
@Lokk
With your method i have to include the whole qt-opengl-library...
instead i convert using qimage.convertToFormat(QImage::Format_ARGB32);
like laurent said...
works like a charm <3
qimage.convertToFormat(QImage::Format_ARGB32);
image.LoadFromPixels(qimage.width(), qimage.height(), reinterpret_cast<const sf::Uint8*>(qimage.bits()));
much thanks to both of you :)
-
Really? SFML wants RGBA, not ARGB. Colors should be wrong in the final texture.
-
Yeah, it's really weird lol...
-
I only tested it with an black/transparent image....
will try...
edit: your right... :/
edit2: OpenGLWidget conversion keeps the colours but flips the y of my image xD not that big deal, but kinda sucks :D
-
i can read and set every pixel, but you cant read the alpha of an pixel from an qimage :O
In fact, it is possible :
QImage image;
...
QRgb pixel = image.pixel(x, y);
int alpha = qAlpha(pixel); // return your alpha component
-
woot? why i didn't find the qAlpha function in the doc? :O
-
Not to be a necromancer on this topic but I just ran into the same problem
here is how I solved it.
QImage res = QImage(320, 320, QImage::Format_ARGB32);
res.load("test.png");
res = res.rgbSwapped();
sf::Image image;
image.Create(res.width(), res.height(), reinterpret_cast<const sf::Uint8*>(res.bits()));