5 Replies Latest reply on Aug 3, 2009 2:49 PM by Mainmanian

    JPEGEncoder issue

    Mainmanian Level 1

      I am encountering a strange behavior in my flex application. I think I am doing somethign silly, but I don't know what. I apprecite any help.

       

      My flex app creates an image using JPEGEncoder of a frame of a video that I play. When I run on my local dev machine (XP running Flex 3.2 and Tomcat app server using BlazeDS), the encoder creates a picture and everythign is great. When I run the same software on my test environment (Fedore Linux, Tomcat and Blaze DS), the picture it encodes is all black.

       

      I realize that in both cases, my pc is running teh swf and the encoding is getting done locally and hence my frustration on why it does not work on text env. Does anybody have any though on why this might be happening? Thanks

       

      My code is below:

       

                  private function playheadUpdateHandler(event:VideoEvent):void{
                      if((!jpegCreated) && (videoDisplay.playheadTime >= 10)){
                           var bmData:BitmapData = new BitmapData(520,280); 
                           bmData.draw(this.videoDisplay); 
                           var bm:Bitmap = new Bitmap(bmData); 
                           var jpgenc:JPEGEncoder = new JPEGEncoder(100);
                          var imageByteArray:ByteArray = jpgenc.encode(bmData);
                         
                          //file upload
                             var token:AsyncToken = AsyncToken(
                                                       FileUtility.doUpload(imageByteArray,jpegPath)
                                                       );
                             token.addResponder(new AsyncResponder(asyncResult,asyncFault));       
                             jpegCreated = true;
                        }
                  }
                  private function asyncFault(event:FaultEvent):void{
                      SimpleLog.write("Upload fault generated");
                  }
                  private function asyncResult(event:ResultEvent,token:AsyncToken):void{
                      SimpleLog.write("CreateCourseJPEG.mxml: AsyncResult :" + event.result);
                      if(event.result.toLowerCase()=="success"){
                          videoDisplay.removeEventListener(VideoEvent.PLAYHEAD_UPDATE, playheadUpdateHandler);
                          this.removeAllChildren();
                          var e:TextEvent = new TextEvent("finishedThumbnail",true,false,"finished");
                          dispatchEvent(e);
                      }
                  }

        • 1. Re: JPEGEncoder issue
          Gregory Lafrance Level 6

          I'm wondering if this is a side effect of not setting the compiler option -use-network=true  ?

           

          The dev environment is more forgiving, but once an app is on the server, this can have unintended consequences.

           

          If this post answers your question or helps, please mark it as such.

          • 2. Re: JPEGEncoder issue
            Mainmanian Level 1

            Hi Greg, thansk for your note. Unfortunately, setting the compiler option -use-network=true did not work. The images are still all black. That was an inspired idea though :-)

            • 3. Re: JPEGEncoder issue
              Mainmanian Level 1

              Greg, based on your thinking of network, I tried setting the Endianness of the ByteArray (teh array into which the encoded image lives) to littleEndian by imgaeByteArray.endian = "littleEndian";  (This is puzzling me, so I am throwing the kitchen sink at it)

               

              However, upon debugging, I see that the statement had no effect; the imageByteArray was still "bigEndian". Any idea why?

               

              Below is the modified code.

               

                              if((!jpegCreated) && (videoDisplay.playheadTime >= 10)){
                                  var imageByteArray:ByteArray = new ByteArray;
                                  imageByteArray.endian = "littleEndian";
                                   var bmData:BitmapData = new BitmapData(520,280); 
                                   bmData.draw(this.videoDisplay); 
                                   var bm:Bitmap = new Bitmap(bmData); 
                                   var jpgenc:JPEGEncoder = new JPEGEncoder(80);
                                  imageByteArray = jpgenc.encode(bmData);
                                  //var imageByteArray:ByteArray = jpgenc.encode(bmData);
                                  trace(" CreateCourseJPEG jpg file len: ",imageByteArray.length);
                                 
                                  //file upload
                                  SimpleLog.write("CreateCourseJPEG.mxml: JPG file length is " + imageByteArray.length.toString());
                                     var token:AsyncToken = AsyncToken(
                                                               FileUtility.doUpload(imageByteArray,jpegPath)
                                                               );
                                     token.addResponder(new AsyncResponder(asyncResult,asyncFault));       
                                     jpegCreated = true;

              • 4. Re: JPEGEncoder issue
                Mainmanian Level 1

                I just tested it by settign the endian prop after the array was filled with data and the settign seemed to have worked. It is puzzling why settign teh prop before fillign it with data would not work. Thanks

                • 5. Re: JPEGEncoder issue
                  Mainmanian Level 1

                  Greg, one other datapoint in this issue is that, on the local dev env, teh file size is roughly 140K while the file size when I run it from my test Linux server env is 4592. Seems to be a significant difference. Does this help you help me? Thanks