Click here to Skip to main content
15,923,689 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
Private ReadOnly oldimage As Image = .....


Private Sub drawnewimage()
Dim newimage As Image = oldimage
*Draw over newimage*
End Sub

*Display old image*
The old image gets overwritten. How do copy instead of overwrite?
Posted

1 solution

The question makes little sense because it is based on not understanding one of the most fundamental concept, reference types. Assignment copies references, not objects themselves. You don't "overwrite" anything, you just copy reference to the same object and then modify the same object.

What you want is called cloning. Please see, for example, https://msdn.microsoft.com/en-us/library/system.drawing.image.clone%28v=vs.110%29.aspx[^].

However, understanding the problem is much more important than the solution, including this trivial solution. First of all, you should understand clearly what happens in your example. Be careful: you cannot really successfully do any programming before you perfectly understand reference and value types, and probably a lot more.

—SA
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900