Visualizzazione dei risultati da 1 a 2 su 2

Discussione: Stampa immagini

  1. #1

    Stampa immagini

    Salve,

    girando per la rete ho trovato e personalizzato questo codice :

    codice:
    import java.awt.*;
    import java.awt.event.*;
    import java.awt.image.ImageObserver;
    import javax.swing.*;
    import java.awt.print.*;
    
    public class Print implements Printable, ActionListener {
    
    
        public int print(Graphics g, PageFormat pf, int page) throws
                                                            PrinterException {
    
            if (page > 0) { /* We have only one page, and 'page' is zero-based */
                return NO_SUCH_PAGE;
            }
    
            /* User (0,0) is typically outside the imageable area, so we must
             * translate by the X and Y values in the PageFormat to avoid clipping
             */
            Graphics2D g2d = (Graphics2D)g;
            g2d.translate(pf.getImageableX(), pf.getImageableY());
    
            /* Now we perform our rendering */
            
            Toolkit toolkit=Toolkit.getDefaultToolkit();
            Image img=toolkit.getImage("ScreenShoot.png");
            System.out.println(img.getSource());
            
            
            ImageObserver o=new ImageObserver() {
    
                public boolean imageUpdate(Image img, int infoflags, int x, int y, int width, int height) {
                  
                    while ((infoflags & ALLBITS) == 0) {                
    
    }            return true;    // throw new UnsupportedOperationException("Not supported yet.");
                }
            };
            
            g.drawImage(Toolkit.getDefaultToolkit().getImage("ScreenShot.png"), 0, 0,o);
           
            //g.drawString("Hello world!", 100, 100);
    
            /* tell the caller that this page is part of the printed document */
            return PAGE_EXISTS;
        }
    
        public void actionPerformed(ActionEvent e) {
             PrinterJob job = PrinterJob.getPrinterJob();
             job.setPrintable(this);
             boolean ok = job.printDialog();
             if (ok) {
                 try {
                      job.print();
                 } catch (PrinterException ex) {
                  /* The job did not successfully complete */
                 }
             }
        }
    
        public static void main(String args[]) {
     
            UIManager.put("swing.boldMetal", Boolean.FALSE);
            JFrame f = new JFrame("Hello World Printer");
            f.addWindowListener(new WindowAdapter() {
               public void windowClosing(WindowEvent e) {System.exit(0);}
            });
            JButton printButton = new JButton("Print Hello World");
            printButton.addActionListener(new Print());
            f.add("Center", printButton);
            f.pack();
            f.setVisible(true);
        }
    il problema è che non stampa tutta l'immagine , come mai?

    inoltre dove devo intervenire per stampare le img in verticale?
    E' tutta colpa di Berlusconi !
    Help [Ciclico] Fisco, domande varie

    Avatar

  2. #2
    penso sia dovuto al caricamento dell'img ma non so come controllare l'avvenuto caricamento, suggerimenti?
    E' tutta colpa di Berlusconi !
    Help [Ciclico] Fisco, domande varie

    Avatar

Permessi di invio

  • Non puoi inserire discussioni
  • Non puoi inserire repliche
  • Non puoi inserire allegati
  • Non puoi modificare i tuoi messaggi
  •  
Powered by vBulletin® Version 4.2.1
Copyright © 2025 vBulletin Solutions, Inc. All rights reserved.