Home

Operations on Bitmaps: Copying a Picture

     

Description

Copying a picture is the process of getting each pixel of a picture from one document, the source, and reproducing it on another document, the target:

Copying a Picture

This operator is easy. from the source, get the (x, y) coordinate of a pixel and assign it to the corresponding (x, y) coordinate on the target document. This can be done as follows:

Copying a Picture

private void btnCopy_Click(object sender, EventArgs e)
{
    Graphics graph = pbxSource.CreateGraphics();
    Bitmap bmpSource = (Bitmap)pbxSource.Image;
    Bitmap bmpDestination =
                new Bitmap(pbxDestination.ClientSize.Width,
                           pbxDestination.ClientSize.Height);

    int width = bmpSource.Width;
    int height = bmpSource.Height;

    for (int x = 0; x < width; x++)
    {
        for (int y = 0; y < height; y++)
        {
            Color clr = bmpSource.GetPixel(x, y);
            bmpDestination.SetPixel(x, y, clr);
        }
    }

    pbxDestination.Image = bmpDestination;
}

Copying a Picture

 
 

Home Copyright © 2010-2014, FunctionX