2 Replies Latest reply on Jul 19, 2006 6:11 AM by Chunick

    Create transparent Images with imaging Lingo

    Level 7
      Hi

      I need some example. how to crate one bitmap castmember out of two.
      Example - I have two numbers ("3" and "5") as bitmap castmembers with
      transparent background
      I want to create castmember, containing number "35" with transparent
      background

      Any help will be appreciated

      Thanx in advance
      LM


        • 1. Re: Create transparent Images with imaging Lingo
          Level 7
          You might find it easier in your situation to calculate the size
          required, combine the alphas of the 2 different numbers into the correct
          location of a #grayscale bitmap with the appropriate dimensions, and use
          this as the alpha channel for a solid colour image - assuming both your
          number bitmaps are the same, solid colour.
          For example, the following #movie handler might get you started (watch
          for unintentional line wrapping):
          --
          on mCombineImages i1, i2, col
          if ( ilk(i1, #member) = 1 ) then i1 = i1.image
          if ( ilk(i2, #member) = 1 ) then i2 = i2.image
          if ( ilk(col, #color) = 0 ) then col = color(#rgb, 0, 0, 0)

          if ( ilk(i1, #image) = 0 ) then return #error
          if ( ilk(i2, #image) = 0 ) then return #error

          r1 = i1.rect
          r2 = i2.rect
          r = r1.union(r2.offset(r1.width, 0))

          i = image(r.width, r.height, 32)
          OK = i.fill(i.rect, col)
          if OK <> 1 then return #error

          a = image(r.width, r.height, 8, #grayscale)
          OK = a.copyPixels( i1.extractAlpha(), r1.offset(0, (r.height -
          r1.height)/2), r1 )
          if OK <> 1 then return #error
          OK = a.copyPixels( i2.extractAlpha(), r2.offset(r1.width, (r.height -
          r2.height)/2), r2 )
          if OK <> 1 then return #error

          OK = i.setAlpha(a)
          if OK <> 1 then return #error
          i.useAlpha = 1
          return i
          end
          • 2. Re: Create transparent Images with imaging Lingo
            Chunick Level 3
            I think there may be a few options, depending on the reason why you need to combine two digits to create a number. It seems like you might be using the number for a game.

            The general method I would start off with is getting the image from a text member in the cast (or creating the text member from scratch and getting the image). Here's a simple bit of code you can do in the message window:

            txtmem = new(#text)
            txtmem.text = "35"
            txtmem.fontSize = 32
            imgmem = new(#bitmap)
            imgmem.image = txtmem.image.duplicate()

            you'll see that the image is already transparent because the image of the text member contains an alpha channel. If you want to be a bit fancier then you can embed a fancy font and use a behavior I wrote that will allow you to set an outline and dropshadow on the text: http://www.mediamacros.com/item/item=1006687700