Nie jesteś zalogowany.
Jeśli nie posiadasz konta, zarejestruj je już teraz! Pozwoli Ci ono w pełni korzystać z naszego serwisu. Spamerom dziękujemy!
Prosimy o pomoc dla małej Julki — przekaż 1% podatku na Fundacji Dzieciom zdazyć z Pomocą.
Więcej informacji na dug.net.pl/pomagamy/.
Witam.
Stworzyłem sobie program do prostych operacji na plikach graficznych. Mam jednak problem, poniewaz nie moge uruchomic drukowania, sypie bledami.
Moge liczyc na pomoc bardziej doswiadczinych w programowaniu?
Dzieki za wszelką pomoc debianowcy.
klasa main:
/* * To change this template, choose Tools | Templates * and open the template in the editor. */ package javaapplication6; import javax.swing.JFrame; /** * * @author E5500 */ public class Main { /** * @param args the command line arguments */ public static void main(String[] args) { JFrame frame=new Ramka(); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); frame.setVisible(true); // TODO code application logic here } }
Klasa Ramka:
/* * To change this template, choose Tools | Templates * and open the template in the editor. */ package javaapplication6; import java.awt.BorderLayout; import java.awt.Graphics; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; import java.awt.geom.AffineTransform; import java.awt.image.AffineTransformOp; import java.awt.image.BufferedImage; import java.awt.image.BufferedImageOp; import java.awt.image.ByteLookupTable; import java.awt.image.ConvolveOp; import java.awt.image.Kernel; import java.awt.image.LookupOp; import java.awt.image.RescaleOp; import java.io.File; /*import java.io.IOException; import java.util.Arrays; import java.util.Iterator; import java.util.List; import java.util.Set; import java.util.TreeSet; import javax.imageio.IIOImage; import javax.imageio.ImageIO; import javax.imageio.ImageReader; import javax.imageio.ImageWriter; import javax.imageio.stream.ImageOutputStream;*/ import java.io.FileInputStream; import java.io.FileNotFoundException; import java.io.IOException; import javax.imageio.ImageIO; //import javax.swing.ImageIcon; import javax.print.Doc; import javax.print.DocFlavor; import javax.print.DocPrintJob; import javax.print.PrintException; import javax.print.PrintService; import javax.print.PrintServiceLookup; import javax.print.SimpleDoc; import javax.swing.ButtonGroup; import javax.swing.JFileChooser; import javax.swing.JFrame; import javax.swing.JLabel; import javax.swing.JMenu; import javax.swing.JMenuBar; import javax.swing.JMenuItem; import javax.swing.JOptionPane; import javax.swing.JPanel; import javax.swing.JRadioButton; import javax.swing.JRadioButtonMenuItem; import sun.java2d.pipe.SpanShapeRenderer.Simple; /* * To change this template, choose Tools | Templates * and open the template in the editor. */ /** * * @author E5500 */ class Ramka extends JFrame{ public Ramka() { setTitle("Program graficzny"); setSize(1024,786); //panel-transformacje obrazu JPanel panel=new JPanel() { @Override public void paintComponent(Graphics g) { super.paintComponents(g); if (image!=null)g.drawImage(image, 0, 0, null);} }; add(panel, BorderLayout.CENTER); //menu programu JMenuBar menuBar=new JMenuBar(); setJMenuBar(menuBar); JMenu menu=new JMenu("Plik"); JMenu processingimage=new JMenu("Transformacje obrazu"); JMenu about=new JMenu("O programie"); menuBar.add(menu); menuBar.add(processingimage); menuBar.add(about); JMenuItem openitem=new JMenuItem("Otworz Plik"); JMenuItem exititem=new JMenuItem("Wyjscie"); JMenuItem saveitem=new JMenuItem("Zapisz"); JMenuItem printitem=new JMenuItem("Drukuj"); JMenuItem bluritem=new JMenuItem("Blur"); JMenuItem sharpenitem=new JMenuItem("Sharpen"); JMenuItem brightenitem=new JMenuItem("Bright"); JMenuItem edgeitem=new JMenuItem("Edge"); JMenuItem negativeitem=new JMenuItem("Negative"); JMenuItem rotateitem=new JMenuItem("Rotate"); JMenuItem aboutitem=new JMenuItem("O programie"); JMenuItem drukujitem=new JMenuItem("Drukowanie"); menu.add(openitem); menu.add(saveitem); menu.add(printitem); menu.add(exititem); processingimage.add(bluritem); processingimage.add(sharpenitem); processingimage.add(brightenitem); processingimage.add(edgeitem); processingimage.add(negativeitem); processingimage.add(rotateitem); about.add(aboutitem); DocFlavor flavor=DocFlavor.INPUT_STREAM.GIF; addPrintServices(menu, flavor); /*ramka do wyswietlania pogldadu zdjec label=new JLabel(); add(label);*/ openitem.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent event) { openFile(); } }); printitem.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent event) { printFile(); } }); exititem.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent event) { System.exit(0); } }); bluritem.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent event) { float weight=1.0f/9.0f; float[] elements=new float[9]; for(int i=0;i<9;i++)elements[i]=weight; convolve(elements); } }); brightenitem.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent event) { float a=1.1f; float b= -20.0f; RescaleOp op=new RescaleOp(a, b, null); filter(op); } }); edgeitem.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent event) { float[] elements= {0.0f, -1,0f, 0.0f, -1.0f, 4.f, -1,0f, 0.0f, -1.0f, 0.0f }; convolve (elements);} }); sharpenitem.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent event) { float[] elements= { 0.0f, -1.0f, 0.0f, -1.0f, 5.f, -1.0f, 0.0f, -1.0f, 0.0f, }; convolve(elements); } }); negativeitem.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent event) { byte negative[]=new byte[256]; for(int i=0;i<256;i++)negative[i]=(byte)(255-i); ByteLookupTable table=new ByteLookupTable(0, negative); LookupOp op=new LookupOp(table, null); filter(op); } }); rotateitem.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent event) { if(image==null)return; AffineTransform transform=new AffineTransform().getRotateInstance(Math.toRadians(90), image.getWidth()/4, image.getHeight()/4); AffineTransformOp op=new AffineTransformOp(transform, AffineTransformOp.TYPE_BILINEAR); filter(op); } }); aboutitem.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent event) { JOptionPane.showMessageDialog(null, "Program stworzony na przedmiot " + "Warsztaty Programistyczne."); } }); } //drukowanie public void addPrintServices(JMenu menu, DocFlavor flavor) { PrintService[] services=PrintServiceLookup.lookupPrintServices(flavor, null); ButtonGroup group=new ButtonGroup(); for(int i=0;i<services.length;i++) { final PrintService service=services[i]; JRadioButtonMenuItem item= new JRadioButtonMenuItem(service.getName()); menu.add(item); if(i==0) { item.setSelected(true);//currentService!!! currentService=service; } group.add(item); item.addActionListener(new ActionListener() { public void ActionPerformed(ActionEvent event) { currentService=service; } } ); } } //metoda otwierajaca pliki graficzne public void openFile() { JFileChooser chooser=new JFileChooser(); chooser.setCurrentDirectory(new File(".")); chooser.setFileFilter(new javax.swing.filechooser.FileFilter() { public boolean accept(File f) { String name= f.getName().toLowerCase(); return name.endsWith(".gif")||name.endsWith(".jpg")||name.endsWith(".jpeg") || f.isDirectory(); } public String getDescription(){ return "Pliki graficzne"; } } ); int r=chooser.showOpenDialog(Ramka.this); if(r!=JFileChooser.APPROVE_OPTION)return; try { image=ImageIO.read(chooser.getSelectedFile()); } catch (IOException e){ JOptionPane.showMessageDialog(this, e); } repaint(); //fileName=chooser.getSelectedFile().getPath(); //label.setIcon(new ImageIcon(fileName)); } //koniec printService //teraz metoda printfile public void printFile() { try { if(fileName==null)return; if(currentService==null)return; FileInputStream in=new FileInputStream(fileName); DocFlavor flavor=DocFlavor.INPUT_STREAM.GIF; Doc doc=new SimpleDoc(in, flavor,null); DocPrintJob job=currentService.createPrintJob(); job.print(doc, null); } catch (FileNotFoundException e) { JOptionPane.showMessageDialog(this, e); } catch (PrintException e) { JOptionPane.showMessageDialog(this, e); } } private void filter(BufferedImageOp op) { if(image==null)return; BufferedImage filteredImage=new BufferedImage(image.getWidth(), image.getHeight(), image.getType()); op.filter(image, filteredImage); image=filteredImage; repaint(); } //odrysowanie ponowne panela private void convolve(float[] elements) { Kernel kernel=new Kernel(3, 3, elements); ConvolveOp op=new ConvolveOp(kernel); filter(op); } private JLabel label; private String fileName; private BufferedImage image; private PrintService currentService; }
Offline
Klasa Ramka sie nie kompiluje bo:
- brakuje zmiennych image, currentService, fileName
- brakuje metod: convolve, filter
Offline
[quote=0dd]Klasa Ramka sie nie kompiluje bo:
- brakuje zmiennych image, currentService, fileName
- brakuje metod: convolve, filter[/quote]
Dzieki za odzew.
Metody filter i convolve są w kodzie tak samo jak zmienne-spójrz na koniec klasy Ramka :)
Problem jest jeden-wystarczy zahaszować
addPrintServices(menu, flavor);
i kompiluje się bez błedów i działa. Problem jest z drukowaniem, nie wiem jak je uruchomić, aby działało poprawnie.
Pozdrawiam.
Offline
w metodzie printFile() masz:
if(fileName==null)return;
Wydaje mi sie ze fileName zawsze jest null.
Offline
[quote=0dd]w metodzie printFile() masz:
if(fileName==null)return;
Wydaje mi sie ze fileName zawsze jest null.[/quote]
To nie to, problem z addPrintServices(menu, flavor) zniknął, button się pojawił w menu, ale po kliknięciu dalej nie odpala wydruku. Ma ktoś jeszcze jakiś pomysł?
Offline
[quote=sonic81]Witam.
Stworzyłem sobie program do prostych operacji na plikach graficznych. Mam jednak problem, poniewaz nie moge uruchomic drukowania, sypie bledami.
Moge liczyc na pomoc bardziej doswiadczinych w programowaniu?[/quote]
A można liczyć na wklejenie tych błędów?
Offline
Nieaktualne już ale dzięki za pomoc.
Pozdro
Offline
Time (s) | Query |
---|---|
0.00011 | SET CHARSET latin2 |
0.00005 | SET NAMES latin2 |
0.00096 | SELECT u.*, g.*, o.logged FROM punbb_users AS u INNER JOIN punbb_groups AS g ON u.group_id=g.g_id LEFT JOIN punbb_online AS o ON o.ident='18.118.227.199' WHERE u.id=1 |
0.00075 | REPLACE INTO punbb_online (user_id, ident, logged) VALUES(1, '18.118.227.199', 1732965576) |
0.00037 | SELECT * FROM punbb_online WHERE logged<1732965276 |
0.00039 | SELECT topic_id FROM punbb_posts WHERE id=126995 |
0.00005 | SELECT id FROM punbb_posts WHERE topic_id=14900 ORDER BY posted |
0.00046 | SELECT t.subject, t.closed, t.num_replies, t.sticky, f.id AS forum_id, f.forum_name, f.moderators, fp.post_replies, 0 FROM punbb_topics AS t INNER JOIN punbb_forums AS f ON f.id=t.forum_id LEFT JOIN punbb_forum_perms AS fp ON (fp.forum_id=f.id AND fp.group_id=3) WHERE (fp.read_forum IS NULL OR fp.read_forum=1) AND t.id=14900 AND t.moved_to IS NULL |
0.00005 | SELECT search_for, replace_with FROM punbb_censoring |
0.00148 | SELECT u.email, u.title, u.url, u.location, u.use_avatar, u.signature, u.email_setting, u.num_posts, u.registered, u.admin_note, p.id, p.poster AS username, p.poster_id, p.poster_ip, p.poster_email, p.message, p.hide_smilies, p.posted, p.edited, p.edited_by, g.g_id, g.g_user_title, o.user_id AS is_online FROM punbb_posts AS p INNER JOIN punbb_users AS u ON u.id=p.poster_id INNER JOIN punbb_groups AS g ON g.g_id=u.group_id LEFT JOIN punbb_online AS o ON (o.user_id=u.id AND o.user_id!=1 AND o.idle=0) WHERE p.topic_id=14900 ORDER BY p.id LIMIT 0,25 |
0.00068 | UPDATE punbb_topics SET num_views=num_views+1 WHERE id=14900 |
Total query time: 0.00535 s |