HTMLLoader bleibt grau bei BitmapData draw

BMo

Mitglied
Hi,
ich verfolge folgendes Ziel: Ich möchte ein PDF mit dem HTMLLoader einlesen und
die erste Seite als JPG speichern. Einlesen und Anzeigen ist kein Problem. Das speichern auch nicht, nur ist der Teil des Bildes, an dem das PDF sein sollte einfach nur grau.

Gewünschtes Ergebnis siehe Bild 1, leider kommt nur Bild 2 raus. Ich hab es schon mit cacheAsBitmap versucht, aber geht auch nicht.
Hat sonst jemand eine Idee?

Danke!

Grüße
 

Anhänge

  • 1.jpg
    1.jpg
    111,3 KB · Aufrufe: 52
  • 2.jpg
    2.jpg
    7,9 KB · Aufrufe: 49
Code:
import flash.display.BitmapData;
import flash.display.StageScaleMode;
import jpgencoder.*;

Stage["showMenu"]=false;
stage.scaleMode=StageScaleMode.NO_SCALE;

var pdf:HTMLLoader;

function init():void {
	if (HTMLLoader.pdfCapability==HTMLPDFCapability.STATUS_OK) {
		pdf = new HTMLLoader();
		var url:URLRequest=new URLRequest("app:/test.pdf");
		pdf.height=500;
		pdf.width=700;
		pdf.load(url);
		this.pdfEbene.addChild(pdf);
		this.cacheAsBitmap=true;

	}
	this.saveImg.addEventListener('click',function(){;
	pdfLoaded();
	});
	if (HTMLLoader.pdfCapability==HTMLPDFCapability.ERROR_INSTALLED_READER_NOT_FOUND) {
		trace("No reader found");
	}
	if (HTMLLoader.pdfCapability==HTMLPDFCapability.ERROR_INSTALLED_READER_TOO_OLD) {
		trace("Reader is too old");
	}
	if (HTMLLoader.pdfCapability==HTMLPDFCapability.ERROR_PREFERRED_READER_TOO_OLD) {
		trace("Reader is too old");
	}
}

function pdfLoaded():void {
	var BMPData:BitmapData=new BitmapData(this.pdfEbene.width,this.pdfEbene.height);
	BMPData.draw(this.pdfEbene);
	//create a new instance of the encoder, and set the jpeg compression level from 0 to 100
	var jpgenc:JPEGEncoder=new JPEGEncoder(100);
	//encode the bitmapdata object and keep the encoded ByteArray
	var imgByteArray:ByteArray=jpgenc.encode(BMPData);
	//gets a reference to a new empty jpg image file in user desktop
	var fl:File=File.desktopDirectory.resolvePath("snapshot.jpg");
	//Use a FileStream to save the bytearray as bytes to the new file
	var fs:FileStream = new FileStream();
	try {
		//open file in write mode
		fs.open(fl,FileMode.WRITE);
		//write bytes from the byte array
		fs.writeBytes(imgByteArray);
		//close the file
		fs.close();
	} catch (e:Error) {
		trace(e.message);
	}
}

init();
 
Zurück