7 Replies Latest reply on Nov 29, 2006 9:44 AM by duckets

    Annoying copyPixels problem, please help

    Level 7
      Hi

      I have a problem using copyPixels command.

      My task is following:
      1) I have an image castmember with an png imported, that contains some
      number of image objects (for example 10 letters). This image has alpha
      channels
      2) I need to create another image containing just a part of this letters,
      for example 2,4 and 8 letter
      3) I create new image Object and use a copyPixels command to copy the
      letters i need from original to destination image
      4) But, here the problem - if I copy the letters on empty image (with no
      backgroundimage) I get problem with alphachannels - they became "broken", I
      mean, alpha channels are not more transparent es they shell be, but shey are
      shown as white (grey) tattered spots under letters
      5) when before copying the letters I copy to thtn new image some background
      image, and then copy letters - they are shown correct - the alphachannelw
      are OK
      6) when I copy a background image, that is smaller then letters, then the
      part, where copied letter lies over background, is correkt, and the part of
      letter, copied over empty space is "not beautifull"

      I tried to play with parameters of CopyPixels (maskImage, maskOffset,
      something with extractAlpha, useAlpha) but with no success

      Can anyone help me with this
      I need just a line of correct lingo-code?
      Or is this a problem of Director?

      Thanx in advance
      ANY HELP WILL BE APPRECIATED
      Jorg


        • 1. Annoying copyPixels problem, please help, addition
          Level 7
          here some screnshot-examples, demonstration my description
          http://www.lvivmedia.com/fontPr/Fontproblems.jpg






          • 2. Re: Annoying copyPixels problem, please help
            the real POTMO Level 1
            youll have to first copy the images with useAlpha = false to a new image,
            then youll have to copy the alphaChannels of the images to a new 8 bit image
            then youll have to set the image alpha to the new alpha.
            • 3. Re: Annoying copyPixels problem, please help
              Level 7
              Thank you, "the real POTMO" for an answer
              which image should have useAlpha = false, that you mention in first line?

              Could you write a couple lines of code with example sourceImg and destImg
              variables, because i can not figure it out. I've tried already everything
              possoble, but still have the problem. I appreciate very much you answer




              "the real POTMO" <webforumsuser@macromedia.com> wrote in message
              news:ek1moh$o3g$1@forums.macromedia.com...
              > youll have to first copy the images with useAlpha = false to a new image,
              > then youll have to copy the alphaChannels of the images to a new 8 bit
              image
              > then youll have to set the image alpha to the new alpha.
              >


              • 4. Re: Annoying copyPixels problem, please help
                Level 7
                Hi Potmo,
                as you advised, I wrote a function
                on testAlphaChannels sourceImage, cNewWidth, cNewHeight, pRects

                cSourceAlphaImage=sourceImage.extractAlpha()

                newImage = image(cNewWidth, cNewHeight, 32)

                newAlphaImage = image(cNewWidth, cNewHeight, 8)

                repeat with i=1 to pRects.count

                destRect=......

                newImage.copyPixels(sourceImage, destRect, pRects )

                newAlphaImage.copyPixels(cAlphaImage, destRect, pRects
                )

                end repeat

                newImage.useAlpha = TRUE

                newImage.setAlpha(newAlphaImage)

                textMember = new(#bitmap)

                textMember.image=newImage

                end

                But the newAlphaImage is not created correct. When I copy a part bitmap
                (alpha channel of next letter) the previous image is partially overwrited,
                as in my screenshot example http://www.lvivmedia.com/fontPr/fontProblem2.jpg

                What is wrong with this function, and how Can I solve this problem

                Thanx in advance
                Jorg



                "Jorg Mann" <jorg.mann@gmx.de> wrote in message
                news:ek1olv$qav$1@forums.macromedia.com...
                > Thank you, "the real POTMO" for an answer
                > which image should have useAlpha = false, that you mention in first line?
                >
                > Could you write a couple lines of code with example sourceImg and destImg
                > variables, because i can not figure it out. I've tried already everything
                > possoble, but still have the problem. I appreciate very much you answer
                >
                >
                >
                >
                > "the real POTMO" <webforumsuser@macromedia.com> wrote in message
                > news:ek1moh$o3g$1@forums.macromedia.com...
                > > youll have to first copy the images with useAlpha = false to a new
                image,
                > > then youll have to copy the alphaChannels of the images to a new 8 bit
                > image
                > > then youll have to set the image alpha to the new alpha.
                > >
                >
                >


                • 5. Annoying copyPixels problem, please help
                  duckets Level 1
                  I think this is what you'll have to do:

                  Do the copypixels command as per your 2nd result example (where "no background image is used") using destImage.useAlpha = false.

                  Create a new image object which will be used as the alpha channel image (same width & height as the dest image, 8 bit, #greyscale):

                  newAlphaImage = image(destImage.width, destImage.height, 8, #greyscale)

                  Repeat the same copypixels commands for each number, but this time the source image is 'sourceAlphaImage', and the dest Image is this 'newAlphaImage' you just made. And the crucial part, use: [#ink:#darkest] for these operations. This is because you are merging greyscale images which represent the alpha channels of each letter. The darker parts are more opaque, and the lighter parts are more transparent, so you always want to keep the darkest pixels with each copypixels command.

                  Finally: destImage.setAlpha(newAlphaImage)

                  hope this helps!

                  - Ben


                  • 6. Re: Annoying copyPixels problem, please help
                    Level 7
                    Hi Ben.

                    Thank you very much vor your replay
                    but I still can get it
                    Here the code
                    on testAlphaChannels sourceImage, cNewWidth, cNewHeight, pRects

                    cSourceAlphaImage=sourceImage.extractAlpha()

                    newImage = image(cNewWidth, cNewHeight, 32)

                    newImage.useAlpha = FALSE

                    newAlphaImage = image(cNewWidth, cNewHeight, 8)

                    repeat with i=1 to pRects.count

                    destRect=......

                    newImage.copyPixels(sourceImage, destRect, pRects )

                    newAlphaImage.copyPixels(cSourceAlphaImage, destRect, pRects
                    ,
                    [#ink:#darkest])

                    end repeat

                    newImage.useAlpha = TRUE

                    newImage.setAlpha(newAlphaImage)

                    textMember = new(#bitmap)

                    textMember.image=newImage

                    end

                    But the result is not correct. O my example
                    http://www.lvivmedia.com/fontPr/Fontproblems3.jpg image to the left is
                    created on background image, and image to the right - with code above

                    What is wrong in the code, I quoted above?
                    Any help will be appreciated

                    Jorg

                    "duckets" <webforumsuser@macromedia.com> wrote in message
                    news:ekhekq$c6g$1@forums.macromedia.com...
                    > I think this is what you'll have to do:
                    >
                    >
                    >
                    > Do the copypixels command as per your 2nd result example (where "no
                    background
                    > image is used") using destImage.useAlpha = false.
                    >
                    > Create a new image as a blank alpha channel image (8 bit, #greyscale)
                    >
                    > Repeat the same copypixels commands for each number, but this time the
                    source
                    > image is 'sourceAlphaImage', and the dest Image is this new alpha image.
                    And
                    > the crucial part, use: [#ink:#darkest] for these operations. This is
                    because
                    > you are merging greyscale images which represent the alpha channels of
                    each
                    > letter. The darker parts are more opaque, and the lighter parts are more
                    > transparent, so you always want to keep the darkest pixels with each
                    copypixels
                    > command.
                    >
                    > hope this helps!
                    >
                    > - Ben
                    >
                    >
                    >
                    >


                    • 7. Re: Annoying copyPixels problem, please help
                      duckets Level 1
                      can you assign the newAlphaImage to a cast member, so that you can see what the alpha result looks like?

                      it's difficult to give futher advice without having the source movie to inspect.

                      - Ben