![]() |
Microsoft Visual Basic/GDI+ Operations: Copying a Picture |
|
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:
Public Class Exercise
Private Sub btnCopy_Click(ByVal sender As System.Object,
ByVal e As System.EventArgs) Handles btnCopy.Click
Dim clr As Color
Dim graph As Graphics
Dim bmpSource As Bitmap
Dim bmpDestination As Bitmap
Dim x As Integer, y As Integer
Dim intHeight As Integer, intWidth As Integer
graph = pbxSource.CreateGraphics()
bmpSource = pbxSource.Image ' CType(pbxSource.Image, Bitmap)
bmpDestination = New Bitmap(pbxDestination.ClientSize.Width,
pbxDestination.ClientSize.Height)
intWidth = bmpSource.Width
intHeight = bmpSource.Height
For x = 0 To intWidth - 1
For y = 0 To intHeight - 1
clr = bmpSource.GetPixel(x, y)
bmpDestination.SetPixel(x, y, clr)
Next
Next
pbxDestination.Image = bmpDestination
End Sub
End Class
This would produce:
|
|
|
|
||
| Home | Copyright © 2010-2016, FunctionX | |
|
|
||