Drawing to a mask

I am not very experienced with masks. In my project, I draw with the graphics on my mask. I get a NilObjectException error unless I set a depth. How do I prevent this NilObjectException without the depth. I basically want to apply a mask.

Thanks

You always set a depth … and the depth is set as part of creating the Picture Object… .not the mask specifically

P=new picture(100,100,32) ' create a 100x100 picture with depth of 32 [full color]
g=p.graphics ' set a pointer to the pictures top layer
m=p.mask
' draw stuff

for the most part you deal with the mask lay using the same commands as the main layer… but usually only in shades of GRAY to define varying levels of transparency. with BLACK and WHITE being on both ends of that scale

[quote=52896:@Dave S]You always set a depth … and the depth is set as part of creating the Picture Object… .not the mask specifically

P=new picture(100,100,32) ' create a 100x100 picture with depth of 32 [full color]
g=p.graphics ' set a pointer to the pictures top layer
m=p.mask
' draw stuff

for the most part you deal with the mask lay using the same commands as the main layer… but usually only in shades of GRAY to define varying levels of transparency. with BLACK and WHITE being on both ends of that scale[/quote]
I am not sure if you know what I am trying to do.

I am trying to make a mask for the picture which I have got, with a transparent mask.

Thanks

I know exactly what you are trying to do.

  1. create a picture object that same size as your existing picture (I am assuming it to NOT have an alpha level)
  2. using code simlar to above. use DRAWPICTURE to place your image on the main layer
  3. now fill in the pixels on the mask layer with black or white as they correspond to pixels on the main layer (hint RGBSURFACE)

it is up to you to decide what gets masked and not.

[advice. be careful how you word your responses… if people take the content of your words wrong… you won’t get much help.
Instead of “you don’t know what I’m doing”… turn it around… say “Here is what I am trying to do, and I’m not sure I understand how your suggestion applies… could you please explain it more… Thank you”]

[quote=52900:@Dave S]I know exactly what you are trying to do.

  1. create a picture object that same size as your existing picture (I am assuming it to NOT have an alpha level)
  2. using code simlar to above. use DRAWPICTURE to place your image on the main layer
  3. now fill in the pixels on the mask layer with black or white as they correspond to pixels on the main layer (hint RGBSURFACE)

it is up to you to decide what gets masked and not.

[advice. be careful how you word your responses… if people take the content of your words wrong… you won’t get much help.
Instead of “you don’t know what I’m doing”… turn it around… say “Here is what I am trying to do, and I’m not sure I understand how your suggestion applies… could you please explain it more… Thank you”][/quote]

Thanks, I tried being polite. But I will word my responses better next time.

I want to mask everything that is transparent. Please could you give me the code to make a picture. I do not know if it has an ‘alpha level’ but the picture already has some transparent pixels. I am basically trying to create a new instance of a picture with the same alpha mask. So basically I am trying to make a full clone of another picture. I could just set it to be the picture I would want to clone. But I want to be able to individually edit that picture. You have done well explaining what I need to do. But I am unsure on what I should write to code this.

Thanks

Btw I would have thought there would be a better method of doing this, rather than manually manipulating the pixels.

If if already has a mask … just copy it using DRAWPICTURE.
If the “mask” is all the pure white pixels… then just set TRANSPARENT=1

If some pixels are transparent, then a mask exists. If you want OTHER pixels to be transparent… then it is up to you to decide which ones.

Dave, you’re a little behind the times it seems. Pictures do not require a depth now. Pictures without a depth are fully transparent, and can have transparent pixels without the use of a mask.

Oliver, if you want to get a mask for a transparent picture, use Picture.CopyMask. You can change the mask however you like, then apply it back using Picture.ApplyMask.

Masks and alpha channels, although very similar, serve different functions. Thanks to CopyMask and ApplyMask, alpha channel pictures can do everything masked pictures can do, but not the reverse. For example, let’s say you have two icons you want to merge on top of each other into a third picture and preserve transparency. The two source images can be either masked or alpha, but the third destination picture must be alpha, or you will never be able to correctly remove the background.

So short version: use CopyMask to get a mask for an alpha picture and use ApplyMask to set the mask for an alpha picture.

If all you need is to get a mask as separate picture from a pic file, I just use Brad Rhine’s old PNG Mask extractor program. Just drag and drop the PNG onto it and click a button, done. But if you are wanting to work with masks from code, you should follow the advice up above.

[quote=52926:@Thom McGrath]Dave, you’re a little behind the times it seems. Pictures do not require a depth now. Pictures without a depth are fully transparent, and can have transparent pixels without the use of a mask.

Oliver, if you want to get a mask for a transparent picture, use Picture.CopyMask. You can change the mask however you like, then apply it back using Picture.ApplyMask.

Masks and alpha channels, although very similar, serve different functions. Thanks to CopyMask and ApplyMask, alpha channel pictures can do everything masked pictures can do, but not the reverse. For example, let’s say you have two icons you want to merge on top of each other into a third picture and preserve transparency. The two source images can be either masked or alpha, but the third destination picture must be alpha, or you will never be able to correctly remove the background.

So short version: use CopyMask to get a mask for an alpha picture and use ApplyMask to set the mask for an alpha picture.[/quote]
Thanks to all.

[quote=52926:@Thom McGrath]Dave, you’re a little behind the times it seems. Pictures do not require a depth now. Pictures without a depth are fully transparent, and can have transparent pixels without the use of a mask.

Oliver, if you want to get a mask for a transparent picture, use Picture.CopyMask. You can change the mask however you like, then apply it back using Picture.ApplyMask.

Masks and alpha channels, although very similar, serve different functions. Thanks to CopyMask and ApplyMask, alpha channel pictures can do everything masked pictures can do, but not the reverse. For example, let’s say you have two icons you want to merge on top of each other into a third picture and preserve transparency. The two source images can be either masked or alpha, but the third destination picture must be alpha, or you will never be able to correctly remove the background.

So short version: use CopyMask to get a mask for an alpha picture and use ApplyMask to set the mask for an alpha picture.[/quote]
Thankyou so much. All works great now!! :slight_smile: You have made my day, literally.