6 Replies Latest reply on Feb 15, 2009 12:55 PM by Cherax79

    copyPixels problem

    Cherax79 Level 1
      Hello.
      I have problem with copyPixels from alpha'ed images to other img with alpha channel
      Here's my code:

      tSrc = mySourceCiphersImage
      cGfx = image( 84, 27, 32 )
      cGfx.useAlpha = true
      cGfx.copyPixels( tSrc, rect( 60, 0, 84, 27 ), srcRectOfCipher6 )
      cGfx.copyPixels( tSrc, rect( 40, 0, 64, 27 ), srcRectOfCipher5 )
      cGfx.copyPixels( tSrc, rect( 20, 0, 44, 27 ), srcRectOfCipher4 )
      cGfx.copyPixels( tSrc, rect( 0, 0, 24, 27 ), srcRectOfCipher3 )

      the effect is this
      and I want this effect!

      I think the problem is that alpha channel of every next copied cipher overwrittes previous copied pixels so the borders of previous ciphers are just invisible.

      How can I do this as I want ?
        • 1. Re: copyPixels problem
          James Newton, ACP Level 3
          Does this help?

          • 2. Re: copyPixels problem
            Cherax79 Level 1
            Not exactly...

            Yellow lines that you can see in my examples is just background that isnt a part of number object.
            That number object is a "flying" object (parent script) that I want to move over that bkg.
            I create a number image by pasting digit images 1 by 1 for every digit in variable that I want to represent.
            I paste them (with copyPixels) on lingo-created image() so it is independent graphic object.

            I think the problem may lay in merging alpha channels of digits that overlaps each other.
            Maybe there is a way to merge 2 "soft" alpha channels ?

            Anyway, thank You for this example, will be useful for me in other way :)
            • 3. Re: copyPixels problem
              James Newton, ACP Level 3
              Can you post your digit images somewhere so that I can work with them directly, rather than trying to second-guess what you are doing? Thanks.
              • 4. Re: copyPixels problem
                Cherax79 Level 1
                Sure.

                Here Is my digits image: digits

                And here is a full code of my number class (parent script):

                • 5. copyPixels problem
                  James Newton, ACP Level 3
                  Here's how I rearranged your cUpdate() handler to work with my AlphaPaste() method. Although mine may look very different from yours, this is because I have taken most of your hard-coded values and assigned them to variables at the beginning of the handler. It's good practice to define a value only once. The only real changes are:

                  1) I make the cGfx transparent just after I create it
                  2) I call AlphaPaste() and you call copyPixels.

                  I've altered my AlphaPaste() method so that it copies the alpha channel in a separate operation, before reapplying the alpha channel.
                  • 6. Re: copyPixels problem
                    Cherax79 Level 1
                    Almost ;)
                    The only problem is that it hardens alpha channel on the edges of each digit.

                    The best way I found is just copy each digit separately to destination image without alpha.
                    I gues it's little slower then prepare whole number and copy it every enterFrame but I guess I have no option ;)

                    Thank you for your time, I've lerned a lot from your examples code anyway :)