How to prevent the use of the SetPixel method?

I have a class:

class MyPic  
{  
    private Bitmap bmp=null;

    public MyPic(Bitmap b)
    {
          bmp=b;
    }

    public Bitmap Bmp
    {
        get { return bmp; }
    }
}

I created the Bont readonly property, but the user can still modify it using the method SetPixel. How can I prevent this?

+3
source share
1 answer

You can not only call SetPixel, but also get graphics and draw it. Raster images vary in design. If it is important for you that the user cannot change the bitmap, create a copy using the copy constructor before returning it.

http://msdn.microsoft.com/en-us/library/ts25csc8.aspx

+3
source

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


All Articles