作为引用对象的位图操作
我正在使用一个位图对象,我向图像添加注释或版权材料,然后返回修改后的位图。我的问题是位图在沿着链移动时不会保存对其所做的更改。我将其视为引用类型,并假设当它传递给每个类时,它将携带对其所做的更改。我已经验证了 MarkImage() 类内部的代码确实可以正常工作,但是最后调用的代码就是发生更改的代码。
Public Shared Function GetImage(ByVal imageDef As IImageDefinition) As Bitmap
Dim image As Bitmap = Drawing.Image.FromFile(imageDef.Path)
If Not imageDef.Authorization.IsAllowed(AuthKeys.CanViewWithoutCopyright) Then
image = New MarkCopyrightImage(image).MarkImage()
End If
If Not imageDef.Authorization.IsAllowed(AuthKeys.CanViewWithoutAnnotations) Then
image = New MarkAnnotateImage(image).MarkImage()
End If
Return image
End Function
如何将更改写入位图对象,然后将该对象传递给另一个类,同时维护更改?
用 C# 或 VB 回答都可以。
I am working with a Bitmap object that I add annotations or copyright material to the image and then return the modified bitmap. My problem is that the Bitmap won't hold the changes made to it as it moves along the chain. I am treating it as a reference type and would assume that as it gets passed to each class it would carry the changes made to it. I have verified that the code inside of the MarkImage() classes does function, but which ever one gets called last is the one that has changes.
Public Shared Function GetImage(ByVal imageDef As IImageDefinition) As Bitmap
Dim image As Bitmap = Drawing.Image.FromFile(imageDef.Path)
If Not imageDef.Authorization.IsAllowed(AuthKeys.CanViewWithoutCopyright) Then
image = New MarkCopyrightImage(image).MarkImage()
End If
If Not imageDef.Authorization.IsAllowed(AuthKeys.CanViewWithoutAnnotations) Then
image = New MarkAnnotateImage(image).MarkImage()
End If
Return image
End Function
How do I write changes to a bitmap object and then pass that object to another class while maintaining the changes?
Answers in C# or VB are fine.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
也许尝试将修改后的位图分配给临时变量,然后用临时变量的内容覆盖
image
。示例:在这些行之间,您可以检查
image
和temp_image
以确保您的函数返回修改后的对象而不是原始对象。Perhaps try assigning the modified bitmap to a temporary variable, then overwrite
image
with the contents of the temporary variable. Example:In between these lines, you can examine
image
andtemp_image
to make sure your functions are returning the modified object and not the original object.