Jump to content
  • Advertisement
Sign in to follow this  

[.net] Bitmap.Clone()

This topic is 3598 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Does this method actually do a deep copy? The Microsoft docs claim it does, but either I'm missing something or the docs or wrong (i.e. the former is the case). I get a bitmap, clone it and then do some destructive processing of the clone - but this also appears to affect the original bitmap (literally all I'm doing is face.Image = (Bitmap)originalImage.Clone();; face then does some levels work (amongst other things), but, at viewing, both face.Image and originalImage appear to have been altered).

Share this post


Link to post
Share on other sites
Advertisement
For questions like this, Reflector will probably be your best friend.


public Bitmap Clone(Rectangle rect, PixelFormat format)
{
if ((rect.Width == 0) || (rect.Height == 0))
{
throw new ArgumentException(SR.GetString("GdiplusInvalidRectangle", new object[] { rect.ToString() }));
}
IntPtr zero = IntPtr.Zero;
int status = SafeNativeMethods.Gdip.GdipCloneBitmapAreaI(rect.X, rect.Y, rect.Width, rect.Height, (int) format, new HandleRef(this, base.nativeImage), out zero);
if ((status != 0) || (zero == IntPtr.Zero))
{
throw SafeNativeMethods.Gdip.StatusException(status);
}
return FromGDIplus(zero);
}



Judging by the name of GdipCloneBitmapAreaI, it looks like it. Unfortunately this isn't the best example of Reflector's usefulness. ;)

Share this post


Link to post
Share on other sites
Hm, that's interesting. I've used Reflector occasionally before, but didn't realize that it could scrutinize the libraries (although, thinking about it, it makes sense - they're no different from normal assemblies).

I've got very odd things happening that I'm totally bamboozled, so it's quite possible that this wasn't actually the problem.

Cheers!

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

Participate in the game development conversation and more when you create an account on GameDev.net!

Sign me up!