作为引用对象的位图操作

发布于 2024-08-25 10:30:36 字数 731 浏览 13 评论 0原文

我正在使用一个位图对象,我向图像添加注释或版权材料,然后返回修改后的位图。我的问题是位图在沿着链移动时不会保存对其所做的更改。我将其视为引用类型,并假设当它传递给每个类时,它将携带对其所做的更改。我已经验证了 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

南渊 2024-09-01 10:30:36

也许尝试将修改后的位图分配给临时变量,然后用临时变量的内容覆盖image。示例:

temp_image = New MarkCopyrightImage(image).MarkImage()
image = temp_image

在这些行之间,您可以检查 imagetemp_image 以确保您的函数返回修改后的对象而不是原始对象。

Perhaps try assigning the modified bitmap to a temporary variable, then overwrite image with the contents of the temporary variable. Example:

temp_image = New MarkCopyrightImage(image).MarkImage()
image = temp_image

In between these lines, you can examine image and temp_image to make sure your functions are returning the modified object and not the original object.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文