简体   繁体   English

在 AS3 (Flash CS3) 中打印影片剪辑

[英]Printing Movieclip in AS3 (Flash CS3)

I know there's similar question on this forum but I've tried the ideas posted and they didn't work.我知道这个论坛上有类似的问题,但我已经尝试过发布的想法,但没有奏效。

Basically we're trying to print a movieclip that contains graphics drawn by the user.基本上,我们正在尝试打印一个包含用户绘制的图形的影片剪辑。 We have a rectangle that serves as the canvas, and some of the drawing may be outside of this canvas.我们有一个矩形作为 canvas,有些图形可能在这个 canvas 之外。 What we're trying to do is to print just what is in the canvas, which does not start at (0,0).我们要做的是打印 canvas 中的内容,它不是从 (0,0) 开始的。 The canvas also needs to be resized before printing to fit properly on the paper. canvas 还需要在打印前调整大小以正确适合纸张。

We were wondering if anyone has a solution to this?我们想知道是否有人对此有解决方案? We've tried a lot of different things but things are always either cut off or sized wrong, or even stretched improperly.我们尝试了很多不同的东西,但总是被剪掉或尺寸错误,甚至拉伸不当。

Here's our super messy code!这是我们超级混乱的代码!

    function startPrint(evnt: Event) {
printJob = new PrintJob();
var xNumber:Number = allGraphic.x; //saving the original x-value of the movieclip
var yNumber:Number = allGraphic.y; //saving y
var wNumber:Number = allGraphic.width; //saving width
var hNumber:Number = allGraphic.height; //saving height
var rect:Rectangle = new Rectangle (0,0,0,0); //printArea

var sucess = printJob.start();

if (sucess) {
if (printJob.orientation == PrintJobOrientation.LANDSCAPE) {
//allGraphic.rotation = 90;
rect.x = 115;
rect.y = 107;
rect.width = 792;
rect.height = 576;
allGraphic.width = 792;
allGraphic.height = 576;
} //end if (landscape)
             else {
rect.x = 110; //x coor of the printArea rectangle
rect.y = 85; //y coor
rect.width = 875; //width of printArea
rect.height = 475; // height of printArea
allGraphic.width = allGraphic.width *(576/wNumber); //scale the movieclip width (with the drawing)
allGraphic.height = allGraphic.height * (396/hNumber); // height scaling    
}//end else

printJob.addPage (allGraphic, rect);
}//end

 if success

//reset allGraphic back to original size
allGraphic.x = xNumber;
allGraphic.y = yNumber;
allGraphic.width = wNumber;
allGraphic.height = hNumber;
}

The problem comes with using allGraphic.width .使用allGraphic.width会出现问题。 This is the complete width of the drawing area, including the negative and positives overlaps.这是绘图区域的完整宽度,包括负片和正片重叠。 You should also use scaleX and scaleY instead of setting a width and height for the scaling (Going back is only a call to scaleX = scaleY = 1 ).您还应该使用scaleXscaleY而不是设置缩放的宽度和高度(返回只是对scaleX = scaleY = 1的调用)。

I would advise to use the fixed dimensions of the canvas where the user can draw for your scale calculations.我建议使用 canvas 的固定尺寸,用户可以在其中绘制用于您的比例计算。 Also you can apply a mask with the size of your canvas to "cut" the overlapping drawings.您也可以使用 canvas 大小的mask来“剪切”重叠的图纸。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM