var bmd:BitmapData = new BitmapData(com.width, comp.height); bmd.draw(comp, new Matrix()); var bm:Bitmap = new Bitmap(bmd);
private function saveFile():void { var zoomSliderVisibleBeforePrint:Boolean; if (map.zoomSliderVisible) { map.zoomSliderVisible = false; zoomSliderVisibleBeforePrint = true; } var printJob:FlexPrintJob = new FlexPrintJob(); var h:Number = printJob.pageHeight; var w:Number = printJob.pageWidth; //VGROUP var printBox:VGroup = new VGroup(); printBox.styleName = "PrintBox"; printBox.width = map.width; //VGROUP inner var printBoxTitle:VGroup = new VGroup(); var printBoxSubTitle:VGroup = new VGroup(); var selectedAlign:String = LRCa[LRCcbo.selectedIndex]; printBox.horizontalAlign=LRCa[LRCcbo.selectedIndex].toString().toLocaleLowerCase(); this.addChild(printBox); try { //TITLE var printTitle:Label = new Label(); printTitle.text = txtTitle.text; if (titleFontSize!=0) { printTitle.setStyle("fontSize", titleFontSize); } else { printTitle.setStyle("fontSize", h / 12); } if (titleFontWeight!="") printTitle.setStyle("fontWeight", titleFontWeight); printTitle.percentWidth = 100; printBoxTitle.addElement(printTitle); //SUBTITLE var printSubtitle:Label = new Label(); printSubtitle.text = txtSubtitle.text; if (subtitleFontSize!=0) { printSubtitle.setStyle("fontSize", subtitleFontSize); } else { printSubtitle.setStyle("fontSize", h / 24); } if (subtitleFontWeight!="") { printSubtitle.setStyle("fontWeight", subtitleFontWeight); } printSubtitle.percentWidth = 100; printBoxSubTitle.addElement(printSubtitle); printBox.addElement(printBoxTitle); printBox.addElement(printBoxSubTitle); //MAP var bmpMap:BitmapData = ImageSnapshot.captureBitmapData(map); var printImg:BitmapImage = new BitmapImage(); printImg.smooth = true; printImg.source = bmpMap; printBox.addElement(printImg); //COPYRIGHT var now:Date = new Date(); var printCopy:Label = new Label(); printCopy.text = copyright + " " + now.toLocaleString() + "."; if (copyrightFontSize!=0) { printCopy.setStyle("fontSize", copyrightFontSize); } else { printCopy.setStyle("fontSize", h / 48); } if (copyrightFontWeight!="") { printCopy.setStyle("fontWeight", copyrightFontWeight); } printCopy.percentWidth = 100; printBox.addElement(printCopy); //COMMENTS if(txtComments.textFlow.getText()) { var spacerLabel:Label = new Label(); spacerLabel.text = " "; //set the comment title: var printCommentTitleLabel:Label = new Label(); printCommentTitleLabel.setStyle("fontSize", h / 24); printCommentTitleLabel.text = "Comments: "; //set the comments: var printComment:Label = new Label(); printComment.setStyle("fontSize", h / 48); printComment.text = txtComments.textFlow.getText(); //add to container: var printBoxComments:VGroup = new VGroup(); printBoxComments.percentWidth = 100; printBoxComments.addElement(spacerLabel); printBoxComments.addElement(printCommentTitleLabel); printBoxComments.addElement(printComment); printBox.addElement(printBoxComments); } } finally { } var bd:BitmapData = new BitmapData(printBox.width, printBox.height); //ArgumentError: Error #2015: Invalid BitmapData. bd.draw(printBox, new Matrix()); var pngEnc:PNGEncoder = new PNGEncoder(); var imgData:ByteArray = pngEnc.encode(bd); fileReference = new FileReference(); fileReference.save(imgData,"TIGER.png"); }
printBox.width = map.width; printBox.height = map.height;
printBox.addEventListener(Event.ADDED_TO_STAGE, printBoxReady); this.addChild(printBox); function printBoxReady(e:Event):void { // code to turn your printbox into bitmapdata and encode to png // and initialize your filereference }
finally { printBox.addEventListener(Event.ADDED_TO_STAGE, printBoxReady); this.addChild(printBox); }
function printBoxReady(e:Event):void { var bd:BitmapData = new BitmapData(printBox.width, printBox.height); bd.draw(printBox, new Matrix()); var pngEnc:PNGEncoder = new PNGEncoder(); var imgData:ByteArray = pngEnc.encode(bd); fileReference = new FileReference(); fileReference.save(imgData,"TIGER.png"); }
// I commented out this line of code // where printImg is created //printBox.addElement(printImg); // I added this listener printBox.addEventListener(Event.ADDED_TO_STAGE, function(e:Event):void { trace("added to stage"); printBox.addElement(printImg); });
var fr:FileReference = new FileReference(); fr.save(printData, "TIGER.png");
Aangemelde leden kunnen berichten plaatsen, updates volgen en meer. Nieuw hier? Registreer een gratis account.
Find useful guides, FAQs, and documents to help you navigate and make the most of Esri Community.