» »

[Netbeans-Java]Embossing,blurring,sharpening

[Netbeans-Java]Embossing,blurring,sharpening

flow123 ::

Imam problem pri nalogi:
Datoteko s sliko odprete in jo preberete preko opcije Open menuja File, z uporabo razreda ImageIO, ki podpira nekaj formatov shranjevanja slik. Za prikaz slike uporabite vsebovalnik ploščo (JPanel), v katerega izrišete sliko (Image ali BufferedImage). Program naj ima dodan menu Edit, kjer so dodane tri opcije, s katerimi lahko nad prebrano sliko izvedemo relief (embossing), glajenje (blurring) ali ostrenje (sharpening).

Ne vem kako naj nad prebrano sliko izvedem npr. blurring. Prosim za pomoč.
Koda:
public class Naloga10 extends javax.swing.JFrame {

    /** Creates new form Naloga10 */
    public Naloga10() {
        initComponents();
        


    }

<em>    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">
    private void initComponents() {

        jPanel1 = new javax.swing.JPanel();
        jMenuBar1 = new javax.swing.JMenuBar();
        jMenu1 = new javax.swing.JMenu();
        file1 = new javax.swing.JMenuItem();
        save = new javax.swing.JMenuItem();
        jMenu2 = new javax.swing.JMenu();
        blur = new javax.swing.JMenuItem();
        sharp = new javax.swing.JMenuItem();

        setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);

        jPanel1.setAutoscrolls(true);

        javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1);
        jPanel1.setLayout(jPanel1Layout);
        jPanel1Layout.setHorizontalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGap(0, 341, Short.MAX_VALUE)
        );
        jPanel1Layout.setVerticalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGap(0, 334, Short.MAX_VALUE)
        );

        jMenu1.setText("Open");

        file1.setText("File");
        file1.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                file1ActionPerformed(evt);
            }
        });
        jMenu1.add(file1);

        save.setText("Save");
        jMenu1.add(save);

        jMenuBar1.add(jMenu1);

        jMenu2.setText("Edit");

        blur.setText("Blurring");
        blur.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                blurActionPerformed(evt);
            }
        });
        jMenu2.add(blur);

        sharp.setText("Sharpen");
        sharp.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                sharpActionPerformed(evt);
            }
        });
        jMenu2.add(sharp);

        jMenuBar1.add(jMenu2);

        setJMenuBar(jMenuBar1);

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jPanel1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap(86, Short.MAX_VALUE))
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addGap(38, 38, 38)
                .addComponent(jPanel1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap(55, Short.MAX_VALUE))
        );

        pack();
    }// </editor-fold></em>

    private void file1ActionPerformed(java.awt.event.ActionEvent evt) {                                      
        

				if (fc.showOpenDialog(jPanel1) == JFileChooser.APPROVE_OPTION) {
					try {
						img = ImageIO.read(this.fc.getSelectedFile());
						jPanel1.repaint();
					} catch (final Exception e) {
					}
				}
                                jPanel1.repaint();

    }                                     

    private void blurActionPerformed(java.awt.event.ActionEvent evt) {                                     
       
    
    }                                    

    private void sharpActionPerformed(java.awt.event.ActionEvent evt) {
        
        
    }
    

    @Override
        public void update(final Graphics g) {
                    paint(g);
        }
    @Override
        public void paint(final Graphics g) {
		super.paint(g);
                int w=jPanel1.getX()+70;
                int h=jPanel1.getY()+70;
				
		g.drawImage(img,w, h, null);
                        
		
	}
        public void blur() {
            
            float data[] = { 0.0625f, 0.125f, 0.0625f, 0.125f, 0.25f, 0.125f,
                0.0625f, 0.125f, 0.0625f };
            Kernel kernel = new Kernel(3, 3, data);
            ConvolveOp convolve = new ConvolveOp(kernel, ConvolveOp.EDGE_NO_OP,
                null);
            convolve.filter(biSrc, biDest);
            bi = biDest;

        }
        public void sharpen() {
            
            float data[] = { -1.0f, -1.0f, -1.0f, -1.0f, 9.0f, -1.0f, -1.0f, -1.0f,
                -1.0f };
            Kernel kernel = new Kernel(3, 3, data);
            ConvolveOp convolve = new ConvolveOp(kernel, ConvolveOp.EDGE_NO_OP,
                null);
            convolve.filter(biSrc, biDest);
            bi = biDest;
       }


    /**
    * @param args the command line arguments
    */
    public static void main(String args[]) {
        java.awt.EventQueue.invokeLater(new Runnable() {
            public void run() {
                new Naloga10().setVisible(true);
            }
        });
    }
    
    BufferedImage biSrc;
    BufferedImage biDest; // Destination image is mandetory.
    BufferedImage bi; // Only an additional reference.
    JFileChooser fc = new JFileChooser();
    BufferedImage img = null;
    // Variables declaration - do not modify
    private javax.swing.JMenuItem blur;
    public javax.swing.JMenuItem file1;
    private javax.swing.JMenu jMenu1;
    private javax.swing.JMenu jMenu2;
    private javax.swing.JMenuBar jMenuBar1;
    private javax.swing.JPanel jPanel1;
    private javax.swing.JMenuItem save;
    private javax.swing.JMenuItem sharp;
    // End of variables declaration

}

nightrage ::

Pa še appletek imaš zraven.
http://www.jhlabs.com/ip/blurring.html

flow123 ::

Jah,sam nevem kako to v mojo kodo vtaknit(netbeans) :|. Ne bi celega programa spreminjala, tko da prosim kko "glavco" za pomoč, ker že kar nekaj časa probavam, pa očitno ne kapiram zadeve.

Spura ::

Naj uganem. Si 4. letnik FRI in ne znas niti trohice programirat.

flow123 ::

Sem s pomočjo linka zgoraj(hvala nightrage) mi je uspelo narest zdej.
@Spura:ne, nisem 4.letnik in ne obvladam še programiranja(Mogoče čez par let ;)in vem, da se moram še dost naučit).

Spura ::

No hvala bogu. Ker ne bos verjela, ampak tocno to se je delalo pri vajah pri predmetu Racunalnisko Zaznavanje, in je bilo presenetljivo stevilo ljudi, ki niso znal uporabit image APIja.

t3hn0 ::

ah, mi mamo tud tocno to za narest pri uporabniskih vmesnikih :)

Za emboss sem uporabi to metodo: http://www2.java.net/article/2005/12/07...
*dela ok

blur in sharpen pa delam po tem principu: http://www.java2s.com/Code/Java/2D-Grap...
sam dobim error "Exception in thread "AWT-EventQueue-0" java.awt.image.ImagingOpException: Unable to convolve src image"
^.^

t3hn0 ::

aha, sem ugotovil kaj je vzrok errorja: http://bugs.sun.com/bugdatabase/view_bu...

prvi post vse pove
^.^


Vredno ogleda ...

TemaSporočilaOglediZadnje sporočilo
TemaSporočilaOglediZadnje sporočilo
»

Vprašanje iz Jave

Oddelek: Programiranje
7819 (559) illion
»

Mala pomoč pri javi

Oddelek: Programiranje
8790 (621) Serial
»

[Java] Ne zažene appleta

Oddelek: Programiranje
5917 (850) iggy
»

[Java]Vprašanja

Oddelek: Programiranje
241743 (1211) Bela01
»

[NALOGA][Java] Težave pri pisanju slikarja

Oddelek: Programiranje
201875 (1517) l0g1t3ch

Več podobnih tem