Sign in to follow this  

loading in an alpha channel with a texture

This topic is 4401 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

(Note: I am using managed direct3d in c#) I am trying to load an alpha channel in with my texture and for some reason my code is crashing. Perhaps there is a better way to do this?
Bitmap Bit = (Bitmap) Image.FromFile( "image.bmp" );
for( int i = 0; i < Bit.Width; i++ )
for( int j = 0; j < Bit.Height; j++ )
{
    Color color = Bit.GetPixel(i,j);
    Bit.SetPixel( i, j, Color.FromArgb( 128, color.R, color.G, color.B ) );
}
Tex = new Texture(device, Bit.Width, Bit.Height, 1, Usage.None, Format.A8B8G8R8, Pool.Managed ); 
Surface surf = Tex.GetSurfaceLevel(0);
Graphics gfx = surf.GetGraphics();
gfx.DrawImage( Bit, 0, 0, Bit.Width, Bit.Height );
gfx.Dispose();



Share this post


Link to post
Share on other sites
Why not instead of using a bitmap, use a png? They have built in alpha channels, and DirectX will use the alpha channel.

I'm not sure about the managed functions for loading textures, but I know it's in there. I use the D3DXCreateTextureFromFileEx() in c++, and that loads the alpha channel as well.

Share this post


Link to post
Share on other sites

This topic is 4401 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this