打印 jpg
我一直在尝试打印动态加载的 jpg,由于某种原因,它永远不会按比例打印,不确定我做错了什么,所以这就是我到目前为止所做的
var request:URLRequest = new URLRequest(getAbsPath("pages/" + pagePrint + "_big.jpg"));
var loader:Loader = new Loader();
loader.load(request);
loader.contentLoaderInfo.addEventListener(Event.COMPLETE, completeHandler);
var frame:Sprite = new Sprite()
function completeHandler(event:Event):void {
var picture:Bitmap = Bitmap(loader.content);
var bitmap:BitmapData = picture.bitmapData;
var matrix:Matrix = new Matrix();
matrix.scale(1, 1);
frame.graphics.beginBitmapFill(bitmap, matrix, true);
frame.graphics.drawRect(0, 0, bitmap.width, bitmap.height);
frame.graphics.endFill();
addChild(frame);
frame.visible = false;
printPage();
}
function printPage ():void {
var myPrintJob:PrintJob = new PrintJob();
var options:PrintJobOptions = new PrintJobOptions();
options.printAsBitmap = true;
myPrintJob.start();
try {
myPrintJob.addPage(frame, null, options);
}
catch(e:Error) {
trace ("Had problem adding the page to print job: " + e);
}
try {
myPrintJob.send();
}
catch (e:Error) {
trace ("Had problem printing: " + e);
}
}
出于某种原因,只需要图像的一部分并且将其炸毁以填充整个页面... jpg 尺寸为 1280x1656,我希望它打印整个 jpg... 有什么想法我做错了吗?
I've been trying to print a dynamically loaded jpg and for some reason it's never printing to scale, not sure what I'm doing wrong so here's what I've done so far
var request:URLRequest = new URLRequest(getAbsPath("pages/" + pagePrint + "_big.jpg"));
var loader:Loader = new Loader();
loader.load(request);
loader.contentLoaderInfo.addEventListener(Event.COMPLETE, completeHandler);
var frame:Sprite = new Sprite()
function completeHandler(event:Event):void {
var picture:Bitmap = Bitmap(loader.content);
var bitmap:BitmapData = picture.bitmapData;
var matrix:Matrix = new Matrix();
matrix.scale(1, 1);
frame.graphics.beginBitmapFill(bitmap, matrix, true);
frame.graphics.drawRect(0, 0, bitmap.width, bitmap.height);
frame.graphics.endFill();
addChild(frame);
frame.visible = false;
printPage();
}
function printPage ():void {
var myPrintJob:PrintJob = new PrintJob();
var options:PrintJobOptions = new PrintJobOptions();
options.printAsBitmap = true;
myPrintJob.start();
try {
myPrintJob.addPage(frame, null, options);
}
catch(e:Error) {
trace ("Had problem adding the page to print job: " + e);
}
try {
myPrintJob.send();
}
catch (e:Error) {
trace ("Had problem printing: " + e);
}
}
For some reason that only takes one part of the image and blows it up to fill an entire page... the jpg dimentions are 1280x1656 and I would like it to print the entire jpg... Any ideas what I'm doing wrong?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
在您尝试打印之前,我会适当缩放剪辑。
您可以通过以下方式获取输出页面的像素宽度和高度:
并据此设置框架的 .scaleX 和 .scaleY 。
(在每个版本的 Flash Player 中,打印处理都是出了名的垃圾;恐怕您必须自己做很多工作......)
I'd scale the clip appropriately before you try printing.
You can get the pixel width and height of the output page with:
And set the .scaleX and .scaleY of the frame based on that.
(Print handling is notoriously rubbish in every version of the Flash Player; you have to do a lot of work yourself, I'm afraid...)
我猜测您的图像正在以 72dpi 的默认分辨率发送到打印后台处理程序,因此它会很大(在 1280x1656 下,这是一个 17.777" x 23" 图像),所以我猜测您只看到左上角大部分部分适合物理打印页面。
要解决此问题,您可以缩小图像以适合页面(可能至少为 0.45 左右比例),但由于 72dpi 分辨率仍然相当低,因此显示的细节较少。或者你可以使用第二种方法,即将DPI设置为更准确地适合你想要的打印尺寸(可能是300dpi左右)
如果你需要重置图像的内部DPI,这是我见过的唯一方法(但是没有亲自尝试)是Flex SDK中的ImageSnapshot类。您可以使用它以特定 DPI 提取位图数据,然后可以将该位图数据发送到 PrintJob。
ImageSnapshot.captureBitmapData() 文档
此外,还有一个更快、更容易的尝试...如果您正在加载的 JPEG 图像文件确实具有较高的 DPI,那么当您执行 BeginBitmapFill() 时,该 DPI 可能会丢失。您可以尝试将位图添加为“框架”的子项而不是绘制它吗?这可以为您正确保留分辨率。
I'm guessing that your image is being sent to the print spooler at default resolution of 72dpi, so it's coming out huge (at 1280x1656 that's a 17.777" x 23" image) so I'm guessing you're seeing only the top left most portion fitting on the physical printed page.
To solve this, you can either scale the image down to fit on the page (probably to about .45 scale at least) which will come out with less detail dues to it still being a fairly low 72dpi resolution. Or you can use the second approach, which is to set the DPI to be more accurate for your desired print size (probably 300dpi or so)
If you need to reset the internal DPI of the image, the only method I've seen (but not tried personally) is the ImageSnapshot class in the Flex SDK. You can use it to extract BitmapData at a specific DPI, then you could send that BitmapData to the PrintJob.
ImageSnapshot.captureBitmapData() Documentation
Also, a quicker easier thing to try... If the JPEG image file you're loading does have a higher DPI, that is probably being lost when you do your BeginBitmapFill(). Could you try adding the Bitmap as a child of 'frame' rather than drawing it? That may preserve the resolution properly for you.