|
Copying a picture is the process of getting each pixel
of a picture from one document, the source, and reproducing it on another
document in the exact same location (x and y coordinates), the target:
|
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:
System::Void btnCopy_Click(System::Object^ sender, System::EventArgs^ e)
{
Graphics ^ graph = pbxSource->CreateGraphics();
Bitmap ^ bmpSource = reinterpret_cast<Bitmap ^>(pbxSource->Image);
Bitmap ^ bmpDestination =
gcnew Bitmap(pbxTarget->ClientSize.Width,
pbxTarget->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);
}
}
pbxTarget->Image = bmpDestination;
}
This would produce: