New topic: 

MASKING help

<http://forums.realsoftware.com/viewtopic.php?t=46689>

         Page 1 of 1
   [ 6 posts ]                 Previous topic | Next topic          Author  
Message        DaveS          Post subject: MASKING helpPosted: Thu Jan 24, 
2013 10:17 pm                                 
Joined: Sun Aug 05, 2007 10:46 am
Posts: 4459
Location: San Diego, CA                I have the following code (which doesn't 
work right, hence this plea for help)

I need to draw a ROUND RECTANGLE filled with a Pattern.

DRAW_PATTERN returns a SQUARE RECTANGLE with the pattern in it.
Then I am trying to MASK the RoundRect part.

G is another picture, where the PatternFilled RoundRect will end up.
If I want to draw it OPAQUE  (If option_Draw_Opaque=0) then I get exactly what 
I want

but if I want to make any WHITE INSIDE the RoundRect also transparent (If 
option_Draw_Opaque=1) it does NOT work
and the RoundRect is displayed as SOLID BLACK

I look for BLACK in the mask if pixel(xx,yy).red=0 and white in the Image by 
looking at the R/G/B ... seems =&CFFFFFF doesn't work.

' Create a CrossHatch Filled Picture
p=Draw_Pattern(x,y,w,h,pat_id)
' Mask off Picture
m=p.Mask.Graphics
m.ForeColor=&cffffff
m.FillRect 0,0,w,h
' Set the RoundRect portion to Transparent
m.ForeColor=&c000000
m.fillroundrect 0,0,w,h,arcw,arch

///// good to this point as long as option_Draw_Opaque=0

' if =1 then we want any part of the Pattern that is WHITE to be Transparent 
also
If option_Draw_Opaque=1 Then
  rsG=p.RGBSurface ' Top layer (with crosshatch)
  rsM=p.Mask.RGBSurface ' Mask Layer already masked to RoundRect Shape
  //
  // Scan the Bounding Rectangle.  If Mask=Black and Image is White.. Set Mask 
to White also so it will be transparent
  //
  For yy=0 To h
  For xx=0 To w
  clr=rsG.Pixel(xx,yy)
  If rsM.pixel(xx,yy).red=0 And clr.red=255 and clr.green=255 and clr.blue=255 
Then ' black
    rsM.pixel(xx,yy)=&cffffff
  End If
  Next xx
  Next yy
End If
// Now plaster Masked image on to MAIN graphic area
g.DrawPicture p,x,y,w,h, 0,0,w,h
      
_________________
Dave Sisemore
MacPro, OSX Lion 10.7.4 RB2012r1
Note : I am not  interested in any solutions that involve custom Plug-ins of 
any kind  
                             Top                timhare          Post subject: 
Re: MASKING helpPosted: Thu Jan 24, 2013 11:08 pm                         
Joined: Fri Jan 06, 2006 3:21 pm
Posts: 12015
Location: Portland, OR  USA                Have DrawPattern do the work.

Create a picture object.
Fill the mask with white (transparent).
Draw each line in the pattern.
Draw that same line in black in the mask (opaque).

The result is an image where the space between the crosshatches is transparent.

Make another picture object.
Fill its mask with black (opaque).
Draw a white round rect in the mask (transparent)
Draw the pattern into the picture.

Tim   
                             Top                DaveS          Post subject: 
Re: MASKING helpPosted: Fri Jan 25, 2013 1:22 am                                
 
Joined: Sun Aug 05, 2007 10:46 am
Posts: 4459
Location: San Diego, CA                The problem with that is two-fold

1) If the pattern is to be transparent is optional.. maybe the user wants that, 
maybe they don't (hence the option_DrawOpaque flag)
2) Sometimes the pattern can't be transparent... if there is TWO non-white 
colors involved.


Also, the Patterns are BitMap templates stored as 32x32 tiles in a PNG file 
(which is Black/White only). Color is applied using TRANSFORM maps..

This is why I want/need to apply the transparency via a MASK.... and I cannot 
figure out why the posted code is not producing the results I desire.      
_________________
Dave Sisemore
MacPro, OSX Lion 10.7.4 RB2012r1
Note : I am not  interested in any solutions that involve custom Plug-ins of 
any kind  
                             Top                HMARROQUINC          Post 
subject: Re: MASKING helpPosted: Fri Jan 25, 2013 1:42 am                       
          
Joined: Sun Jan 25, 2009 5:11 pm
Posts: 344
Location: Guatemala, Central America                Not topic related but... 
Your Personal information link is down and the screenshot for Fotofixer is 
missing. 

Sincerely, 
The web police

     
_________________
Future RS guru  
                             Top                timhare          Post subject: 
Re: MASKING helpPosted: Fri Jan 25, 2013 2:06 am                         
Joined: Fri Jan 06, 2006 3:21 pm
Posts: 12015
Location: Portland, OR  USA                DaveS wrote:' Mask off Picture
m=p.Mask.Graphics
m.ForeColor=&cffffff
m.FillRect 0,0,w,h
' Set the RoundRect portion to Transparent
m.ForeColor=&c000000
m.fillroundrect 0,0,w,h,arcw,arch


You have the colors reversed here. &cffffff is transparent, &c000000 is opaque.

EDIT: nvm, the code is right, the comment is wrong.  

' Set the RoundRect portion to Opaque   
                             Top                timhare          Post subject: 
Re: MASKING helpPosted: Fri Jan 25, 2013 2:20 am                         
Joined: Fri Jan 06, 2006 3:21 pm
Posts: 12015
Location: Portland, OR  USA                I copied your code into a canvas, 
dimmed all the variables and it works both ways.  There's something else going 
on.  I assume this is part of a larger piece of code and your image is getting 
trashed in the parts you didn't show us.   
                             Top             Display posts from previous: All 
posts1 day7 days2 weeks1 month3 months6 months1 year Sort by AuthorPost 
timeSubject AscendingDescending          Page 1 of 1
   [ 6 posts ]      
-- 
Over 1500 classes with 29000 functions in one REALbasic plug-in collection. 
The Monkeybread Software Realbasic Plugin v9.3. 
http://www.monkeybreadsoftware.de/realbasic/plugins.shtml

rbforumnotifier@monkeybreadsoftware.de

Reply via email to