Ichibann
Ichibann

Reputation: 4451

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?

Upvotes: 3

Views: 169

Answers (1)

mihi
mihi

Reputation: 6735

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

Upvotes: 3

Related Questions