Page 1 of 1

[SOLVED]how to get wximage with alpha channel from resources

Posted: Fri Mar 30, 2007 3:12 pm
by idhan
Hi,

I want to display some textures on opengl with transparency. I have some png files load on a xrc resource file. The problem is when I get this png files I use the method "LadBitmap" and after that I use "ConvertToImage" to finally get my wxImage variable. My problem is that I don't get any Alpha Channel after the process and I need this Alpha channel to create the opengl texture.

I know is possible to create wxImage using the follow contructor:

wxImage(wxInputStream& stream, long type = wxBITMAP_TYPE_ANY, int index = -1)

but how can I put a png file on a xrc resource to read it as wxInputStream???

Or maybe is any another way to do what I need...

thanks in advance..

Posted: Mon Apr 02, 2007 6:11 pm
by zhouhao
It should be no problem to load png with alpha channel. I've done simular thing before without any problem.

If you want load a file to input stream. Here is the code:

Code: Select all


      wxFFileInputStream in(_T("example.png"));
      if ( in.IsOK )
      {
          // do whatever you want
      }


Posted: Wed Apr 04, 2007 11:25 am
by idhan
I think you didn't get it,

How can I put a png file with alpha channel into a xrc resource file as wxInputStream, I don need to read it from a file, it must be inside of a xrc resource file...

Anyone have done this???

Posted: Thu Apr 05, 2007 4:24 pm
by idhan
Here is the solution.

After you get you GetBitmap() from you xrc resource and convert it to wxImage with ConvertToImage(). You will get you image that keep you transparency as Mask, so... after that you apply to you image SetMask(true) and if you image doesn't get alpha channel (HasAlpha()) then you apply InitAlpha().

best regards :-)