Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I prevent using SetPixel method?

I have class:

class MyPic  
{  
    private Bitmap bmp=null;

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

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

I made Bmp readonly property but user still can modify it by using SetPixel method. How can I prevent that?

like image 733
Ichibann Avatar asked Feb 03 '26 23:02

Ichibann


1 Answers

You can not only call SetPixel, but also get a Graphics and draw on it. Bitmaps are mutable by design. If it is important to you that the user cannot modify your bitmap, create a copy using the copy constructor before returning it.

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

like image 170
mihi Avatar answered Feb 05 '26 11:02

mihi