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

If you are using the main C++ distribution of wxWidgets, Feel free to ask any question related to wxWidgets development here. This means questions regarding to C++ and wxWidgets, not compile problems.
Post Reply
idhan
Experienced Solver
Experienced Solver
Posts: 88
Joined: Tue Feb 28, 2006 9:03 pm

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

Post 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..
Last edited by idhan on Thu Apr 05, 2007 4:26 pm, edited 1 time in total.
zhouhao
Earned some good credits
Earned some good credits
Posts: 144
Joined: Tue Dec 06, 2005 7:02 am

Post 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
      }

idhan
Experienced Solver
Experienced Solver
Posts: 88
Joined: Tue Feb 28, 2006 9:03 pm

Post 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???
idhan
Experienced Solver
Experienced Solver
Posts: 88
Joined: Tue Feb 28, 2006 9:03 pm

Post 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 :-)
Post Reply