Kurt Griffin <[EMAIL PROTECTED]> wrote:
> I'm copying a dupe of the image of a text member into a dupe of the
> image of a png member. Given the fact that both carry alpha images, the
> result is not surprising - the copypixels op pastes the text in, but
> also cuts a rect the size of the text image out of the background image
> (as in, the alpha is getting copied to, as well as the image).

Hi Kurt,

Try this:

on copyText(anAlphaImage, aTextMember, anOffset) ---------------------
  -- INPUT: <anAlphaImage> should be a 32-bit image object
  --        <aTextMember> should be a text member
  --        <anOffset> may be a point
  -- ACTION: Copies the text of aTextMember onto anAlphaImage.  The
  --         alpha channel is made opaque under the text.
  --------------------------------------------------------------------
  
  tTextImage = aTextMember.image
  tTextRect  = aTextMember.rect
  
  -- Use anOffset to position the text image as required
  if ilk(anOffset, #point) then
    tTargetRect = tTextRect.offset(anOffset.locH, anOffset.locV)
  else
    tTargetRect = tTextRect
  end if
  
  -- Take a copy of the alpha channel before any changes are made
  tAlpha = anAlphaImage.extractAlpha()
  
  -- Copy the text into the rgb channel of the target image, with
  -- anti-aliasing.  This will affect the alpha channel.
  anAlphaImage.useAlpha = FALSE
  anAlphaImage.copyPixels(tTextImage, tTargetRect, tTextRect)
  
  -- Copy a black image of the text into the alpha channel.  This
  -- overcomes a couple of quirks:
  -- * copying the text image itself into the image's alpha channel
  --   will lead to semi-transparent areas where the text is a color
  --   other than black
  -- * copying the text alpha directly into the image alpha using
  --   #darkest ink leads to banding
  
  tBlack = image(tTextRect.width, tTextRect.height, 32, 8)
  tBlack.fill(tTextRect, rgb(0, 0, 0))
  tBlack.setAlpha(tTextImage.extractAlpha())
  
  -- Copy the text alpha data into the image's original alpha channel
  tAlpha.copyPixels(tBlack, tTargetRect, tTextRect)
  
  -- Set the alpha channel of the image to the composite alpha image
  anAlphaImage.setAlpha(tAlpha)
  anAlphaImage.useAlpha = TRUE
end copyText


Cheers,

James

[To remove yourself from this list, or to change to digest mode, go to 
http://www.penworks.com/lingo-l.cgi  To post messages to the list, email 
[EMAIL PROTECTED]  (Problems, email [EMAIL PROTECTED]). Lingo-L is for 
learning and helping with programming Lingo.  Thanks!]

Reply via email to