Are you safe to delete an icon after calling Icon.ToBitmap ()?

After calling System.Drawing.Icon.ToBitmap() to create an image, are you safe to delete the original Icon ?

+3
source share
3 answers

Yes. Icon.ToBitmap draws an icon on a new Bitmap object, so it’s safe to delete it after that.

Edit:
It is interesting to note the Icon.ToBitmap () method in Reflector. I expected this to be a simple call to Graphics.DrawImage or Graphics.DrawIcon, but it is more involved. As long as this is possible, the function will make a copy of the icon image data copy instead, but it will return to calling Graphics.DrawImage or Graphics.DrawIcon if it cannot make the copy. Copying memory is much faster, so this is obviously the reason, but it makes the code much harder to read.

+4
source

The method converts Icon into a new Bitmap object, so there will be no link from Bitmap to Icon .

So yes, it is safe to delete Icon .

+6
source

Yes. If you no longer need the icon and you have a bitmap, you are fine.

0
source

Source: https://habr.com/ru/post/1240362/


All Articles