Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/heroku/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何在java中打印缓冲图像列表_Java_Arrays_Printing_Bufferedimage - Fatal编程技术网

如何在java中打印缓冲图像列表

如何在java中打印缓冲图像列表,java,arrays,printing,bufferedimage,Java,Arrays,Printing,Bufferedimage,是否有任何方法可以在单个打印作业中打印(多个)缓冲图像列表?提前感谢。如果要打印多个图形图像,每页一个,请使用页面索引在这些页面中迭代,并在每页上打印一个。例如,如果在以下数组中表示多个图像: BufferedImage[] images = new BufferedImage[10]; 然后使用print()方法,如以下代码片段所示: public int print(Graphics graphics, PageFormat pageFormat, int pageI

是否有任何方法可以在单个打印作业中打印(多个)缓冲图像列表?提前感谢。

如果要打印多个图形图像,每页一个,请使用页面索引在这些页面中迭代,并在每页上打印一个。例如,如果在以下数组中表示多个图像:

BufferedImage[] images = new BufferedImage[10];
然后使用print()方法,如以下代码片段所示:

public int print(Graphics graphics,
           PageFormat pageFormat, int pageIndex)
           throws PrinterException {

    if (pageIndex < images.length) {
        graphics.drawImage(images[pageIndex], 100, 100, null);
        return PAGE_EXISTS;
    } else {
        return NO_SUCH_PAGE:
    }
}
double pageHeight = pageFormat.getImageableHeight();
/* Draw each line that is on this page.
 * Increment 'y' position by lineHeight
 * for each line.
 */
int y = 0; 
int start = (pageIndex == 0) ? 0 : pageBreaks[pageIndex-1];
int end   = (pageIndex == pageBreaks.length)
                 ? textLines.length : pageBreaks[pageIndex];
for (int line=start; line<end; line++) {
    y += lineHeight;
    g.drawString(textLines[line], 0, y);
}
PageFormat参数描述页面的可打印区域。特别是,要查找页面的垂直跨度,请使用以下代码片段:

public int print(Graphics graphics,
           PageFormat pageFormat, int pageIndex)
           throws PrinterException {

    if (pageIndex < images.length) {
        graphics.drawImage(images[pageIndex], 100, 100, null);
        return PAGE_EXISTS;
    } else {
        return NO_SUCH_PAGE:
    }
}
double pageHeight = pageFormat.getImageableHeight();
/* Draw each line that is on this page.
 * Increment 'y' position by lineHeight
 * for each line.
 */
int y = 0; 
int start = (pageIndex == 0) ? 0 : pageBreaks[pageIndex-1];
int end   = (pageIndex == pageBreaks.length)
                 ? textLines.length : pageBreaks[pageIndex];
for (int line=start; line<end; line++) {
    y += lineHeight;
    g.drawString(textLines[line], 0, y);
}
使用以下代码片段计算适合页面的行数和分页符数:

int linesPerPage = ((int)pageHeight)/lineHeight);
int numBreaks = (textLines.length-1)/linesPerPage;
int[] pageBreaks = new int[numBreaks];
for (int b=0; b < numBreaks; b++) {
    pageBreaks[b] = (b+1)*linesPerPage; 
}
int-linesPerPage=((int)pageHeight)/lineHeight;
int numBreaks=(textLines.length-1)/linesPerPage;
int[]换页符=新的int[numBreaks];
for(int b=0;b
使用print()方法计算可打印面积,原因如下:

文本测量取决于FontRenderContext,这在打印机图形返回的FontMetrics对象中是隐式的,该对象除了在print()方法中之外不可用。 在进行打印之前,不得披露页面格式。因为如果用户在打印对话框中选择了横向模式,则需要考虑此设置。传递到print()方法的PageFormat对象提供此信息。 分页符位置如以下代码片段所示:

public int print(Graphics graphics,
           PageFormat pageFormat, int pageIndex)
           throws PrinterException {

    if (pageIndex < images.length) {
        graphics.drawImage(images[pageIndex], 100, 100, null);
        return PAGE_EXISTS;
    } else {
        return NO_SUCH_PAGE:
    }
}
double pageHeight = pageFormat.getImageableHeight();
/* Draw each line that is on this page.
 * Increment 'y' position by lineHeight
 * for each line.
 */
int y = 0; 
int start = (pageIndex == 0) ? 0 : pageBreaks[pageIndex-1];
int end   = (pageIndex == pageBreaks.length)
                 ? textLines.length : pageBreaks[pageIndex];
for (int line=start; line<end; line++) {
    y += lineHeight;
    g.drawString(textLines[line], 0, y);
}
/*画出这一页上的每一行。
*按线宽增加“y”位置
*每行。
*/
int y=0;
int start=(pageIndex==0)?0:pageBreaks[pageIndex-1];
int end=(pageIndex==pageBreaks.length)
? textLines.length:pageBreaks[pageIndex];

对于(int line=start;line您到目前为止尝试了什么?实际上,我们的问题是打印
多页tiff
文件(几天前我已经问过了)在java中。但是没有得到正确的方法。现在打印多缓冲图像背后的想法是,因为
JAI helper
提供单页缓冲图像。因此我们可以缓冲图像数组,然后再打印它。