6 Replies Latest reply on Feb 16, 2010 2:33 PM by Stickman65

    editing palette index for 256 color bitmap at runtime?

    Stickman65

      Hi all.

       

      I'm a director newbie starting work on what i think will be a very simple project, but i need to do a specific non-newbie thing.  I'm hoping that someone with knowledge of Director can quickly point me in the right direction and save me a ton of frustration.

       

      I'm working with 256 color bitmaps, doing a kind of paint-by-numbers thing, and want to change the entries in a bitmaps palette index on the fly.  When the user clicks on bitmapA, the pixels color is read from the palette index and stored.  When bitmapB is clicked, that palette index value corresponding to that pixel is changed to the stored color.

       

      Can director do this?  should i be looking into lingo, or java script?  I'm in a position where I don't know what i don't know.  I'm looking for someone to tell me what to go learn about to be able to do this.

       

      Thanks in advance for any and all suggestions!

        • 1. Re: editing palette index for 256 color bitmap at runtime?
          James Newton, ACP Level 3

          I'm not sure that I understand what BitmapA and BitmapB represent.  Since you mention painting by numbers, I imagine that you have an image with outlines and white spaces, and that the user is to fill the white spaces with the appropriate colour.  I also imagine that the colours available for a given image are stored somewhere, possibly in a bitmap which looks like an artist's palette of colours.

           

          With the getPixel() method, you can retrieve the colour in an image at a given point.  With the mapStageToMember() method you can convert a point on the Stage to a point in the bitmap image that the user is clicking on.  With the undocumented floodFill() method, you can fill an area in an image with a given colour.

           

          You might like to look at Imaging Lingo in general.  You can find beginner articles here and here.

           

          Does this answer your question?  Or would you like to give more details of exactly what you are trying to achieve?

          1 person found this helpful
          • 2. Re: editing palette index for 256 color bitmap at runtime?
            Stickman65 Level 1

            My bad, i guess "paint by numbers" was a poor analogy for what i'm trying to do.  To be more precise, this is a program to allow the user to design a custom tie dye T-shirt.  BitmapA is, indeed, just a selection of available dye colors.

            BitmapB is an idealized image of a Tie dye t-shirt.  By "idealized", I mean that for, say, a red, green and blue shirt, all the various shades have been reduced to single shades of red, green and blue.  The 256 color palette would then contain entries for red, green, blue.  The remaining 253 entries would be unused.    If the user selects, say, yellow, from bitmapA, (getpixel would work fine for this, thanks) and clicks a blue region on bitmapB, then ALL the 10 or 15 non-contiguous blue portions of the shirt image would be changed to yellow.  Rather than finding and changing the color of every blue pixel in the bitmap, it would be much faster, simpler, and more convenient to simply change the single palette index entry for all those pixels from blue to yellow.  That way, all the information needed to define a shirt design would be the final palette.  The bitmap information would never have to be altered at all.

             

            I hope this is a better description of what I'm trying to do.  Thanks for your help!  I'll check out the resources you mentioned.

            • 3. Re: editing palette index for 256 color bitmap at runtime?
              James Newton, ACP Level 3

              It sounds as if your T-shirt design could be split up into three bitmaps: the background colour shape in one bitmap and the two pattern colour shapes in separate bitmaps.  All shapes can be plain black.  You can place the images in three separate sprites, and set the .color property of each sprite separately.  The black bitmap will now appear in the chosen colour.

               

              Here's a bare-bones demo:

               

              go movie "http://nonlinear.openspark.com/tips/imaging/TShirt.dir"

               

              Click on one of the colour squares then on the T-shirt or the circle.

              1 person found this helpful
              • 4. Re: editing palette index for 256 color bitmap at runtime?
                Stickman65 Level 1

                Wow! A sample program and everything?  That's help above and beyond the call of duty!  thanks!

                 

                I guess that's the way I'll have to do it; it looks simple enough.  Some of the shirts I'm doing will have 40 or 50 color regions (rather than the 3 mentioned in my simple example) so it will be a bit more complicated than just fiddling with the palette, but it certainly seems straightforward enough.

                • 5. Re: editing palette index for 256 color bitmap at runtime?
                  Production Monkey Level 3

                   

                  Cutting your image into 40 or 50 layers sounds like a major pain. If you are using Director 11.x then you can use a single image and manipulate the colors with a byteArray. It should be sufficiently fast for your needs.  The attached file is a D11.5 file with sample color replace code.

                  • 6. Re: editing palette index for 256 color bitmap at runtime?
                    Stickman65 Level 1

                    Perfect!  That's exactly the thing I was looking for!

                     

                    Thanks!  You've saved me many hours!