Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/345.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_Swing_Awt_Java 2d - Fatal编程技术网

Java 而图像的打印太小,无法在一些大型显示器上读取文本

Java 而图像的打印太小,无法在一些大型显示器上读取文本,java,swing,awt,java-2d,Java,Swing,Awt,Java 2d,在生成打印输出时,需要限制图像的大小 允许其可读并允许打印的最小尺寸 输出流到多页宽多页长 如果必要的话。目前它仅限于一页 下面是这个示例代码 public DisplayPrinter(DisplayManager displayManager, PrintPlugin configuration, String header, String footer) { this.displayManager = displayManager; this.config

在生成打印输出时,需要限制图像的大小 允许其可读并允许打印的最小尺寸 输出流到多页宽多页长 如果必要的话。目前它仅限于一页

下面是这个示例代码

public DisplayPrinter(DisplayManager displayManager, PrintPlugin configuration, String header, String footer)
 {
        this.displayManager = displayManager;
        this.configuration = configuration;
        this.header = header;
        this.footer = footer;

        Font configHeaderFont = configuration.getHeaderFont();
        headerFont = (configHeaderFont != null) ? configHeaderFont : defaultHeaderFont;

        Font configFooterFont = configuration.getFooterFont();
        footerFont = (configFooterFont != null) ? configFooterFont : defaultFooterFont;
    }
还有另一种方法

public int print(Graphics g, PageFormat pageFormat, int pageIndex) throws PrinterException {
        if (pageIndex != 0)
            return NO_SUCH_PAGE;

        Graphics2D g2d = (Graphics2D) g;

        Rectangle2D.Double printBounds = new Rectangle2D.Double(
                pageFormat.getImageableX(), 
                pageFormat.getImageableY(),
                pageFormat.getImageableWidth(),
                pageFormat.getImageableHeight()
                );

        // Print the header and reduce the height for printing
        float headerHeight = printHeader(printBounds, g2d);
        printBounds.y += headerHeight;
        printBounds.height -= headerHeight;

        // Carve off the amount of space needed for the footer
        printBounds.height -= getFooterHeight(g2d);

        // Print the nodes and edges
        printDisplay( printBounds, g2d, 0 );

        if (footer != null) {
            printBounds.y += (printBounds.height + 15);
            printFooter(printBounds, g2d);
        }

        return PAGE_EXISTS;
    }
我想打印在大图像的多页图像。和单页的小图像

还有一种方法

protected void printDisplay( Rectangle2D.Double printBounds, Graphics2D g2d, double margin ) {
        // Get a rectangle that represents the bounds of all of the DisplayEntities
        Rectangle r = null;
        for (Enumeration e=displayManager.getEntitySet().getEntityEnumeration();e.hasMoreElements();) {
            DisplayEntity de = (DisplayEntity)e.nextElement();
            if (r == null)
                r = de.getBounds();
            else
                r = r.union(de.getBounds());   
        }

        // Get that as doubles, rather than ints, and expand by half the margin
        // height in all directions
        Rectangle2D.Double entityBounds = new Rectangle2D.Double(r.x,r.y,r.width,r.height);
        entityBounds.x -= margin/2;
        entityBounds.y -= margin/2;
        entityBounds.width += margin;
        entityBounds.height += margin;

        // See if height and/or width was specified
        Unit specifiedSize = configuration.getHeight();
        double printHeight = (specifiedSize != null) ?
            specifiedSize.getValueAsPixels((int)printBounds.height) :
                printBounds.height;

        specifiedSize = configuration.getWidth();
        double printWidth = (specifiedSize != null) ?
            specifiedSize.getValueAsPixels((int)printBounds.width) :
                printBounds.width;

        // Figure out the ratio of print-bounds to the entities' bounds
        double scaleX = 1;
        double scaleY = 1;

        // See if we need to scale
        boolean canExpand = configuration.expandToFit();
        boolean canShrink = configuration.shrinkToFit();

        if (canExpand == false && canShrink == false) {
            scaleX = scaleY = configuration.getScale();
        }
        else {
            if ((canShrink && canExpand) || 
                (canShrink &&
                    (entityBounds.width > printWidth || 
                     entityBounds.height > printHeight)) ||
                (canExpand &&
                    (entityBounds.width < printWidth ||
                     entityBounds.height < printHeight))) {
                scaleX = printWidth / entityBounds.width;
                scaleY = printHeight / entityBounds.height;
            }
        }

        if (configuration.maintainAspectRatio()) { // Scale the same
            if (scaleX > scaleY)
                scaleX = scaleY;
            else 
                scaleY = scaleX;
        }

提前感谢

要更快地获得更好的帮助,请发布.crosspost