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?
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With