views:

13

answers:

1

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? Thanks

A: 

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.

bta