How to duplicate image using BitmapData
<p>I had a situation to duplicate an image with the help of bitmap data, below is the code i used to do the same, am I wrong anywhere, please help me.. Try drawing this image
<a href="http://i.stack.imgur.com/VCSoQ.png" rel="nofollow">http://i.stack.imgur.com/VCSoQ.png</a> in the bmp format</p>

<pre><code>private void button1_Click(object sender, EventArgs e)
{
Bitmap mask = Image.FromFile("../../Data/mask.bmp") as Bitmap;
BitmapData data = mask.LockBits(new Rectangle(0, 0, mask.Width, mask.Height), ImageLockMode.ReadWrite, mask.PixelFormat);
int bytes = Math.Abs(data.Stride) * mask.Height;
byte[] outPut = new byte[bytes];
Marshal.Copy(data.Scan0, outPut, 0, bytes);

Bitmap test = new Bitmap(mask.Width, mask.Height, mask.PixelFormat);
BitmapData testData = test.LockBits(new Rectangle(0, 0, test.Width, test.Height),
ImageLockMode.ReadWrite, test.PixelFormat);
Marshal.Copy(outPut, 0, testData.Scan0, bytes);
test.UnlockBits(testData);
test.Save("test.jpg");
}
</code></pre>

<p>Thanks,
Suresh</p>
