Sign in to follow this  
thuong

how to fix the white border when do transparent the image?

Recommended Posts

after i load my image with WHITE BACKGROUND and do transparent, the white border still remained, can anyone help me how to fix this? m_pd3dDevice->SetRenderState(D3DRS_ALPHATESTENABLE, TRUE); m_pd3dDevice->SetRenderState(D3DRS_ALPHAREF, (DWORD)0x00000001); m_pd3dDevice->SetRenderState(D3DRS_ALPHAFUNC, D3DCMP_GREATEREQUAL); m_pSprite->Begin(NULL); m_pSprite->Draw(m_pEffectTexture, NULL, NULL, NULL, D3DCOLOR_ARGB(0xff,0xff,0xff,0xff)); m_pSprite->End(); m_pd3dDevice->SetRenderState(D3DRS_ALPHATESTENABLE, FALSE);

Share this post


Link to post
Share on other sites
ya, i did set a colour key of white when i created the sprite's texture. what i means is not do transparent for background because it was transparent. i just consider about the WHITE BORDER around the object of the image(etc the WHITE border around the fish of the image).

Share this post


Link to post
Share on other sites
Hi,

Try to use a greater D3DRS_ALPHAREF ... for example 0xBB
The greater alpha ref is, the thinner the borders will be. Alpha ref gives the alpha value at which the pixel are displayed. So if you set alpha ref to 1, the pixel with an alpha greater or equal to 1 (in the range 0-255) will still be displayed. That's where your borders come from.

.:: Paic Citron ::.

Share this post


Link to post
Share on other sites
yeah, what paic set is correct, but there is a way of getting rid of the borders all together but your going to need to edit the sprites a little.
Just fill the alpha of the image with a certain colour( (255,255,0) is often used as a colour key colour) and then set a colour key of that colour in your creation of the texture.
This will display the image without borders.
BTW the borders only occur when applying a filter on the sprite, after sprite->begin is called, you may want to set the filtering to point as this call resets it to linear. With point filtering you wont get any borders but the image will lose the filtering.

Share this post


Link to post
Share on other sites
Guest Anonymous Poster
my image here is not come from loading an image file, it is an dynamic image buffer and its format is 24 bit. I 've try to test with higher alpha value, but no better result at all. I think it is because of the 24 bit buffer's format. Am i right? Is there any way for me to convert the 24 bit buffer to 32 bit buffer?

BYTE *mybimap = buffer;

if(m_pTexture==NULL)
{

D3DSURFACE_DESC ddsd;
if(FAILED(hr=D3DXCreateTextureFromFileInMemoryEx(
m_pD3DDevice,
mybimap,
size,
D3DX_DEFAULT,
D3DX_DEFAULT,
D3DX_DEFAULT,
0,
D3DFMT_A8R8G8B8,
D3DPOOL_MANAGED,
D3DX_FILTER_NONE,
D3DX_FILTER_NONE,
D3DCOLOR_ARGB(0xff,0xff,0xff,0xff),//0xFFFFFFFF,// Color key
//0xFF000000,
NULL,
NULL,
&m_pTexture
)))
return NULL;



// Get texture description and verify settings
if(FAILED(hr = m_pTexture->GetLevelDesc(0, &ddsd)))
return NULL;
m_Format = ddsd.Format;
if(m_Format != D3DFMT_A8R8G8B8 && m_Format != D3DFMT_A1R5G5B5)
MessageBox(NULL,"VFW_E_TYPE_NOT_ACCEPTED","device error",MB_OK);

}
else
{

LPDIRECT3DSURFACE9 targSurf;

m_pTexture->GetSurfaceLevel(0,&targSurf);
if(FAILED(hr=D3DXLoadSurfaceFromFileInMemory(
targSurf,
NULL,
NULL,
mybimap,
size,
NULL,
D3DX_FILTER_NONE,
D3DCOLOR_ARGB(0xff,0xff,0xff,0xff),
NULL)))
return NULL;

Share this post


Link to post
Share on other sites

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