14 Replies Latest reply on Aug 30, 2006 8:05 AM by actionFlash

    flash.display.BitmapData

    actionFlash
      I am importing "flash.display.BitmapData" so that I can use "getPixel" in my flash file.
      It works fine when I view the resulting SWF file that is stored on my laptop in a web browser.
      Once I upload the SWF file to a server and then access it via a browser, "getPixel" does not work anymore.
      Any idea what might be going on?
        • 1. Re: flash.display.BitmapData
          kglad Adobe Community Professional & MVP
          you have a pre-flash 8 flash player version? check:

          http://duber.com/LetsTalk/playerCheck.html
          • 2. Re: flash.display.BitmapData
            actionFlash Level 1
            I have the Player version 8,0,24,0 installed so I don't think that it is an issue with the player.
            It works if a load the file stored on my laptop but not if the same file is stored on a server.
            Hope somebody has an answer ... :)
            • 3. Re: flash.display.BitmapData
              abeall Level 3
              How did you determine that getPixel was not working?
              • 4. Re: flash.display.BitmapData
                kglad Adobe Community Professional & MVP
                then are you using getPixel to determine something about an image that you load into flash and you're failing to ensure the image is loaded before using it?
                • 5. Re: flash.display.BitmapData
                  actionFlash Level 1
                  I am loading jpg images and know that they have loaded because I monitor "bytesTotal".
                  I use "new BitmapData" and then use ".draw" to load the jpg image into the BitmapData object.
                  This works fine if the SWF is stored on the laptop, but when the SWF file is stored on a server, then getPixel is always equal to 16777215 for all pixels and each image ... what is going on?
                  • 6. Re: flash.display.BitmapData
                    abeall Level 3
                    Try using MovieClipLoader instead, and the onLoadInit method:

                    var loader = new MovieClipLoader();
                    loader.loadClip("youimage.jpg",target_mc);
                    loader.addListener(this);
                    function onLoadInit(){
                    //movie has loaded and initialized
                    }
                    • 7. Re: flash.display.BitmapData
                      kglad Adobe Community Professional & MVP
                      there is no bytesTotal and you wouldn't monitor (beyond the first meaningful check) the getBytesTotal() property of your image's load target.

                      show your code.
                      • 8. Re: flash.display.BitmapData
                        actionFlash Level 1
                        Here is my code (I know I "should" specify type my variables, but ...):

                        import flash.geom.Matrix;
                        import flash.display.BitmapData;
                        //
                        analyzeImagesArray = function(imagesArray) {
                        var numImages = imagesArray.length;
                        for (var i = 0; i<numImages; i++) {
                        var currentImage = imagesArray ;
                        var currentWidth = currentImage._width;
                        var currentHeight = currentImage._height;
                        // copying currentImage into BitmapData object
                        var currentBitmap = new BitmapData(Math.floor(currentWidth), Math.floor(currentHeight), false);
                        currentBitmap.draw(currentImage);
                        // compare currentImage with all the images in the array except for currentImage
                        for (var j = 0; j<numImages; j++) {
                        var nextImage = imagesArray[j];
                        // nextImage can't be equal to currentImage
                        if (not (i == j)){
                        var nextWidth = nextImage._width;
                        var nextHeight = nextImage._height;
                        // copying nextImage into BitmapData object
                        var nextBitmap = new BitmapData(Math.floor(nextWidth), Math.floor(nextHeight), false);
                        nextBitmap.draw(nextImage);
                        //
                        var firstBitmap;
                        var secondBitmap;
                        var scaleFactor = 1;
                        // if currentImage is larger then nextImage then scale it to size of nextImage or visa versa
                        if (currentWidth>=nextWidth) {
                        // scale currentImage
                        scaleFactor = nextWidth/currentWidth;
                        firstBitmap = nextBitmap;
                        secondBitmap = currentBitmap;
                        } else {
                        // scale nextImage
                        scaleFactor = currentWidth/nextWidth;
                        firstBitmap = currentBitmap;
                        secondBitmap = nextBitmap;
                        }
                        var scaleMatrix = new Matrix(scaleFactor, 0, 0, scaleFactor, 0, 0);
                        // firstBitmap has the smaller dimensions than the secondBitmap
                        var newSecondBitmap = new BitmapData(firstBitmap.width, firstBitmap.height, false);
                        newSecondBitmap.draw(secondBitmap, scaleMatrix);
                        // the "draw" and "scaleMatrix" produce bitmaps whose pixel values
                        // are all equal to 16777215, using getPixel(x,y)
                        // if the SWF file is stored on the server, whereas this does not happend
                        // when the SWF file is stored on the laptop
                        // Thus, the similarityScore is equal to 1, when the SWF is stored on the server.
                        var similarityScore = computeBitmapSimilarity(firstBitmap, newSecondBitmap, 0.25);
                        if (similarityScore>=0.75) {
                        trace(" .......... IDENTICAL .......... ");
                        }
                        //
                        firstBitmap.dispose();
                        secondBitmap.dispose();
                        newSecondBitmap.dispose();
                        }
                        }
                        }
                        }

                        Hope this helps.
                        Regarding, using a MovieClipLoader, yes, it lets me test if the jpg has loaded.
                        When examine the bytesTotal of the currentImage and nextImage, they indicate that the jpg images have loaded.
                        So, I think, the problem occurs when I "draw" the jpgs into the BitmapObjects.
                        Thank you for all your help.
                        • 9. Re: flash.display.BitmapData
                          abeall Level 3
                          For the sake of us forum users, if you could use the attach code feature for a post then we'd be able to read your code. Otherwise, any time you put [ i ] without the spaces, it gets translated into a BB code for italic text. Also formatting is lost. Thanks.

                          PS - still a good idea to post the code in the message body, because AFAIK newsgorup users -- which there are many -- can't see attached code at all.
                          • 10. Re: flash.display.BitmapData
                            actionFlash Level 1
                            Sorry about posting code without indentations ...
                            • 11. Re: flash.display.BitmapData
                              abeall Level 3
                              > I know I "should" specify type my variables, but ...
                              Nah, I never do.

                              So, that code looks fine, what I'm interested in is the preloading part that you are using to make sure all images are loaded. Loading external images can be a lot trickier than you might think.
                              • 12. Re: flash.display.BitmapData
                                actionFlash Level 1
                                I am using onLoadInit when loading the jpg images ... changed my code and create the BitmapData object and use the draw method to copy the jpg into the BitmapData object inside onLoadInit ... this way I should be sure that the jpg has fully loaded before creating the BitmapData object.
                                As mentioned, it all works when the SWF is on my laptop, but not when stored on the server.
                                After all my testing, I believe that the problem is caused by "BitmapData .draw(...)" not working ...
                                What can I do?
                                • 13. Re: flash.display.BitmapData
                                  abeall Level 3
                                  Why would BitmapData.draw() fail?

                                  Please show us the preloader code. It sounds like you are doing it right, but the only reason I can think of(and a common reason, too) that something would work locally and not online is because dynamically loaded images are not being loaded before code execution. Have you tried simulating download in Flash to see if it gives similar results as online?

                                  I would start debeugging your code online. Create a textfield, and where you would normally do trace() actions, put some more text in the textfield.
                                  • 14. Re: flash.display.BitmapData
                                    actionFlash Level 1
                                    > Why would BitmapData.draw() fail?

                                    Because I monitor many images variables ... had created TextField, as you suggested, that displays "getBytesTotal" and "width" and "height" of the loaded jpg (which is stored not on my server ... and both the local SWF and the server SWF load the same jpg that is stored on different servers) and can see "getBytesTotal" and "width" and "height" when the SWF runs locally or on the server.
                                    All the the info displayed in the TextField using trace is the same for the local and server SWF except for the "getPixel" info, which indicate that "draw" failed to draw the jpg into the BitmapData object because the getPixel values are equal to "white" as if "draw" had not been called.

                                    Appreciate you taking the time and thank you for your help.

                                    Please see below the preloader code:

                                    --------------------------------------------------------------------------------