I have two sections of code which generate a png file from a UIComponent. Both 
seem 
very similar except that one of them cuts the axis titles off for some reason. 
The actual 
image file is generated in Java, but the encoding happens here in flex.  The 
same code is 
used in both calls to Java, though one is through a servlet (which then calls a 
Java method) 
and the other is through a direct call to the remote Java method.  What is 
going on? 

ImageSnapshot.defaultEncoder = PNGEncoder;                              

public function saveAllSnapshots():void {
        for (var i:int=0; i<flowLayout.getChildren().length; i++) {
                var box:VBox = flowLayout.getChildAt(i) as VBox;
                var cp:ChartPanel = box.getChildAt(2) as ChartPanel;
                this.captureImg(cp, cp.title);
        }
}

// creates png ByteArray and sends it to a java remote object for saving 
// This is the method that chops off the axis titles
private function captureImg(comp:UIComponent, name:String):void {    
    var imageSnap:ImageSnapshot = ImageSnapshot.captureImage(comp);
    var imageByteArray:ByteArray = imageSnap.data as ByteArray;
    imgSave.saveImage(imageByteArray, name+"-img.png");  
}

// handle a click on the save image button
private function imgClickHandler(evt:MouseEvent):void {
        var button:Button = evt.target as Button;
        for (var i:int=0; i<flowLayout.getChildren().length; i++) {
                var box:VBox = flowLayout.getChildAt(i) as VBox;
                if (button == box.getChildAt(1)) {
                        saveSnapShot(box.getChildAt(2) as UIComponent);
                        break;
                }
        }               
}

// show image in a new window (this works)
private function saveSnapShot(comp:UIComponent):void {
        var imageSnap:ImageSnapshot = ImageSnapshot.captureImage(comp);
    var imageByteArray:ByteArray = imageSnap.data as ByteArray;

        var request:URLRequest = new URLRequest(imgServURL);
        request.contentType="text/html";
        request.data = imageByteArray;
        request.method = URLRequestMethod.POST;
        navigateToURL(request, "_blank");
}

Reply via email to