本文介绍了NewImage = OldImage会覆盖旧图像的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
-SA —SA
Private ReadOnly oldimage As Image = ..... Private Sub drawnewimage() 昏暗的newimage As Image = oldimage *绘制新图像* 结束子 *显示旧图像* 旧图像被覆盖。如何复制而不是覆盖?
解决方案这个问题没有多大意义,因为它是基于不理解最基本的概念之一,引用类型。赋值复制引用,而不是对象本身。你没有覆盖任何东西,你只需要复制对同一个对象的引用,然后修改同一个对象。 你想要的是什么叫做 cloning 的。请参阅,例如, https:// msdn.microsoft/en-us/library/system.drawing.image.clone%28v=vs.110%29.aspx [ ^ ]。 然而,理解问题比解决方案更重要,包括这个简单的解决方案。首先,您应该清楚地了解您的示例中会发生什么。注意:在完全理解参考和值类型之前,你不可能真正成功地进行任何编程,可能还需要更多。
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?
解决方案 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, msdn.microsoft/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.更多推荐
NewImage = OldImage会覆盖旧图像
发布评论