any can explain the function of stride in bitmapdata?
Stride is there due to hardware requirements that have unfortunately leaked through to the API layer.
It is important because Windows drivers sometimes require that scanlines (rows in the image) be memory aligned. That is why they are sometimes larger than they would strictly need to be.
See for example this MSDN article DIBs and Their Use.
Every scanline is DWORD-aligned. The scanline is buffered to alignment; the buffering is not necessarily 0.
Your handling seems to be sufficient.
Stride is the number of bytes your code must iterate past to reach the next vertical pixel.
This may be different from the image's width * pixel size if hardware requires a width of a certain multiple.
Scanlines are typically aligned on processor word boundaries.
http://javaboutique.internet.com/tutorials/rasters/index2.html has a nice diagram.
People implementing CPU-accessible bitmaps want to align their scanlines on processor word boundaries as the machine codes for accessing and manipulating processor words can be substantially faster than those for non-aligned addresses.