I want to create a rectangle with a hole in it that allows an image/object drawn below to show through the hole. I want to be able to draw multiple pictures/objects in the canvas that have holes that when moved around allow the picture/object below to show through.
I’m trying to create the picture with a hole using a mask like this: (this is in a method that gets four parameters; total width and height and opening width and height)
[code] Dim mPic As Picture
Dim mMask As Picture
Dim x As Integer
Dim y As Integer
mPic = New Picture(matWidth, matHeight)
// draw the picture image
mPic.Graphics.ForeColor = RGB(255, 255, 255) // white
mPic.Graphics.FillRect( 0, 0, mPic.Width, mPic.Height )
mPic.Graphics.ForeColor = RGB(0, 0, 0)
mPic.Graphics.DrawRect( 0, 0, mPic.Width, mPic.Height )
x = (matWidth - openingWidth) / 2
y = (matHeight - openingHeight) / 2
mMask = New Picture(matWidth, matHeight)
mMask.Graphics.ForeColor = RGB(0, 0, 0)
mMask.Graphics.FillRect( x, y, openingWidth, openingHeight )
mPic.ApplyMask(mMask)
image = mPic
[/code]
This code is in a Create method for an object that has a picture property called “image”. I have an array created where I can append all the created objects and then loop through and get the picture to draw.
This just gives me the white filled rectangle with black border. The “hole” does not show anything that is drawn below in the canvas when this picture is drawn. If I change the code and draw the black rectangle in mPic it shows the black rectangle where I want it. But if I try to use the black rectangle as a mask it does not work.
Should this work or do I not understand how drawing multiple pictures in a canvas works? Or where have I gone wrong? I have not been able to find any examples that use ApplyMask.
Thanks.