   error on operating png file
  I try to change leaf shape in png file. In alpha channel, leaf area is white and left area is black. I try to change the RGB value around leaf edge: if the pixel is leaf left edge and alpha < 100 then make the five pixels in the same row before the leaf left edge red. My operating is following but it doesn't work, and the result leaf texture is wrong. Is my operation right? Thank you.Quote:IDirect3DTexture9* pLeafTex = NULL;if(D3D_OK != D3DXCreateTextureFromFile(Device,"leaf.png",&pLeafTex))  MessageBox(NULL,"fail to load leaf texture！","ERROR",0);D3DSURFACE_DESC dd;pLeafTex->GetLevelDesc(0,ⅆ);int leafWidth = dd.Width;//leaf's widthint leafHeight = dd.Height;//leaf's heightD3DLOCKED_RECT LockedRect;if(pLeafTex->LockRect(0,&LockedRect,NULL,0) != D3D_OK)    MessageBox(NULL,"fail to lock texture！","ERROR",0);{D3DXVECTOR4* pColor = (D3DXVECTOR4*)LockedRect.pBits;int pitch = LockedRect.Pitch / sizeof(D3DXVECTOR4);for (int row = 0; row < leafHeight; row++){for (int col = 0; col < leafWidth; col++){if ( pColor[pitch * row + col].w > 100 && pColor[pitch * row + col - 1].w < 100)//leaf's left edge{for (int i = 1; i < 6; i++){pColor[pitch * row + col - i].x = 255;pColor[pitch * row + col - i].y = 0;pColor[pitch * row + col - i].z = 0;}}}}}pLeafTex->UnlockRect(0);//save leaf texture to png fileif (D3DXSaveTextureToFile("newLeaf.png", D3DXIFF_PNG, pLeafTex, NULL) != D3D_OK)MessageBox(NULL,"fail to save texture","ERROR",0);
  D3DXVECTOR4 contains 4 floats, which is 16 bytes. What is the color depth of the texture? If it's 32-bit, then each pixel is only 4 bytes.Also, in the innermost for loop, you need to make sure that the expression used for the array index (pitch * row + col - i) is not less than zero. The same goes for the expression:pitch * row + col - 1a couple of lines above.   