Visualizzazione dei risultati da 1 a 6 su 6
  1. #1

    Scrittura immagine JPEG provoca OutOfMemoryError

    Ciao a tutti, volevo chiedervi come posso risolvere questa situazione di errore:

    Il programma a cui sto lavorando permette di salvare immagini JPEG del pannello da disegno e funziona solo se le dimensioni del pannello sono abbastanza ridotte (per es. non ci sono problemi con dimensioni 1024x768). Ho invece un problema se allargo il pannello.

    In questo caso, infatti, quando tento di scrivere un'immagine JPEG viene scaturito l'errore OutOfMemoryException:
    Exception occurred during event dispatching:
    java.lang.OutOfMemoryError: Java heap space
    at java.awt.image.DataBufferInt.<init>(Unknown Source)
    at java.awt.image.Raster.createPackedRaster(Unknown Source)
    at java.awt.image.DirectColorModel.createCompatibleWr itableRaster(Unknown Source)
    at java.awt.image.BufferedImage.<init>(Unknown Source)
    at SmartConcept$PianoProgettazione.paint(SmartConcept .java:2404)
    at javax.swing.JComponent.paintChildren(Unknown Source)
    at javax.swing.JComponent.paint(Unknown Source)
    at javax.swing.JViewport.paint(Unknown Source)
    at javax.swing.JComponent.paintChildren(Unknown Source)
    at javax.swing.JComponent.paint(Unknown Source)
    at javax.swing.JComponent.paintChildren(Unknown Source)
    at javax.swing.JComponent.paint(Unknown Source)
    at javax.swing.JComponent.paintChildren(Unknown Source)
    at javax.swing.JComponent.paint(Unknown Source)
    at javax.swing.JLayeredPane.paint(Unknown Source)
    at javax.swing.JComponent.paintChildren(Unknown Source)
    at javax.swing.JComponent.paint(Unknown Source)
    at javax.swing.JComponent.paintToOffscreen(Unknown Source)
    at javax.swing.BufferStrategyPaintManager.paint(Unkno wn Source)
    at javax.swing.RepaintManager.paint(Unknown Source)
    at javax.swing.JComponent._paintImmediately(Unknown Source)
    at javax.swing.JComponent.paintImmediately(Unknown Source)
    at javax.swing.RepaintManager.paintDirtyRegions(Unkno wn Source)
    at javax.swing.RepaintManager.paintDirtyRegions(Unkno wn Source)
    at javax.swing.RepaintManager.seqPaintDirtyRegions(Un known Source)
    at javax.swing.SystemEventQueueUtilities$ComponentWor kRequest.run(Unknown Source)
    at java.awt.event.InvocationEvent.dispatch(Unknown Source)
    at java.awt.EventQueue.dispatchEvent(Unknown Source)
    at java.awt.EventDispatchThread.pumpOneEventForFilter s(Unknown Source)
    at java.awt.EventDispatchThread.pumpEventsForFilter(U nknown Source)
    at java.awt.EventDispatchThread.pumpEventsForFilter(U nknown Source)
    at java.awt.Dialog$1.run(Unknown Source)
    Exception occurred during event dispatching:
    java.lang.IllegalArgumentException: im == null!
    at javax.imageio.ImageIO.write(Unknown Source)
    at javax.imageio.ImageIO.write(Unknown Source)
    at SmartConcept.scriviJPEG(SmartConcept.java:549)
    at SmartConcept$SCDialogListener.actionPerformed(Smar tConcept.java:659)
    at javax.swing.JFileChooser.fireActionPerformed(Unkno wn Source)
    at javax.swing.JFileChooser.approveSelection(Unknown Source)
    at javax.swing.plaf.basic.BasicFileChooserUI$ApproveS electionAction.actionPerformed(Unknown Source)
    at javax.swing.AbstractButton.fireActionPerformed(Unk nown Source)
    at javax.swing.AbstractButton$Handler.actionPerformed (Unknown Source)
    at javax.swing.DefaultButtonModel.fireActionPerformed (Unknown Source)
    at javax.swing.DefaultButtonModel.setPressed(Unknown Source)
    at javax.swing.plaf.basic.BasicButtonListener.mouseRe leased(Unknown Source)
    at java.awt.AWTEventMulticaster.mouseReleased(Unknown Source)
    at java.awt.Component.processMouseEvent(Unknown Source)
    at javax.swing.JComponent.processMouseEvent(Unknown Source)
    at java.awt.Component.processEvent(Unknown Source)
    at java.awt.Container.processEvent(Unknown Source)
    at java.awt.Component.dispatchEventImpl(Unknown Source)
    at java.awt.Container.dispatchEventImpl(Unknown Source)
    at java.awt.Component.dispatchEvent(Unknown Source)
    at java.awt.LightweightDispatcher.retargetMouseEvent( Unknown Source)
    at java.awt.LightweightDispatcher.processMouseEvent(U nknown Source)
    at java.awt.LightweightDispatcher.dispatchEvent(Unkno wn Source)
    at java.awt.Container.dispatchEventImpl(Unknown Source)
    at java.awt.Window.dispatchEventImpl(Unknown Source)
    at java.awt.Component.dispatchEvent(Unknown Source)
    at java.awt.EventQueue.dispatchEvent(Unknown Source)
    at java.awt.EventDispatchThread.pumpOneEventForFilter s(Unknown Source)
    at java.awt.EventDispatchThread.pumpEventsForFilter(U nknown Source)
    at java.awt.EventDispatchThread.pumpEventsForFilter(U nknown Source)
    at java.awt.Dialog$1.run(Unknown Source)
    at java.awt.Dialog$3.run(Unknown Source)
    at java.security.AccessController.doPrivileged(Native Method)
    at java.awt.Dialog.show(Unknown Source)
    at java.awt.Component.show(Unknown Source)
    at java.awt.Component.setVisible(Unknown Source)
    at java.awt.Window.setVisible(Unknown Source)
    at java.awt.Dialog.setVisible(Unknown Source)
    at SmartConcept$AscoltoMenuItem.actionPerformed(Smart Concept.java:770)
    at javax.swing.AbstractButton.fireActionPerformed(Unk nown Source)
    at javax.swing.AbstractButton$Handler.actionPerformed (Unknown Source)
    at javax.swing.DefaultButtonModel.fireActionPerformed (Unknown Source)
    at javax.swing.DefaultButtonModel.setPressed(Unknown Source)
    at javax.swing.AbstractButton.doClick(Unknown Source)
    at javax.swing.plaf.basic.BasicMenuItemUI.doClick(Unk nown Source)
    at javax.swing.plaf.basic.BasicMenuItemUI$Handler.mou seReleased(Unknown Source)
    at java.awt.Component.processMouseEvent(Unknown Source)
    at javax.swing.JComponent.processMouseEvent(Unknown Source)
    at java.awt.Component.processEvent(Unknown Source)
    at java.awt.Container.processEvent(Unknown Source)
    at java.awt.Component.dispatchEventImpl(Unknown Source)
    at java.awt.Container.dispatchEventImpl(Unknown Source)
    at java.awt.Component.dispatchEvent(Unknown Source)
    at java.awt.LightweightDispatcher.retargetMouseEvent( Unknown Source)
    at java.awt.LightweightDispatcher.processMouseEvent(U nknown Source)
    at java.awt.LightweightDispatcher.dispatchEvent(Unkno wn Source)
    at java.awt.Container.dispatchEventImpl(Unknown Source)
    at java.awt.Window.dispatchEventImpl(Unknown Source)
    at java.awt.Component.dispatchEvent(Unknown Source)
    at java.awt.EventQueue.dispatchEvent(Unknown Source)
    at java.awt.EventDispatchThread.pumpOneEventForFilter s(Unknown Source)
    at java.awt.EventDispatchThread.pumpEventsForFilter(U nknown Source)
    at java.awt.EventDispatchThread.pumpEventsForHierarch y(Unknown Source)
    at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
    at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
    at java.awt.EventDispatchThread.run(Unknown Source)

    per la scrittura dell'immagine JPEG uso il metodo
    ImageIO.write(pnl.bi, "jpg", fileOUT);

    Il mio pc ha le seguenti caratteristiche:
    1 CPU 1.86 GHz, 2 GB Ram, 40 GB HDD liberi.

    uso l'ambiente di sviluppo Eclipse SDK (Europe ver.) 3.3.0

    Grazie, qualsiasi info è apprezzata
    Daniele.
    90's Commercial listener

  2. #2
    potresti provare a passare alla JVM i seguenti parametri
    -Xms<size> set initial Java heap size
    -Xmx<size> set maximum Java heap size

    così aumenti la memoria che dai a disposizione alla virtual machine

    ciao

  3. #3
    Ok, proverò.

    C'è un modo per passare questi parametri anche con Eclipse?

    Poi volevo chiedere se ci sono soluzioni magari a livello di programmazione Java.
    Grazie.
    90's Commercial listener

  4. #4
    No, si verifica lo stesso problema.
    90's Commercial listener

  5. #5
    Con Eclipse di preciso non saprei...

    cmq con RAD (che dovrebbe avere dei menu simili)
    vai su Esegui -> Esegui... -> Applicazione Java
    sotto ad Applicazione Java ci dovrebbe essere la tua classe main
    la selezioni e vai sul secondo panellino (x)Argomenti e li trovi
    Argomenti di programma
    e
    Argomenti VM

    per eventuali soluzioni a livello di programmazione Java bisogna entrare nel codice e vedere se è possibile fare delle ottimizzazioni

  6. #6
    con Eclipse bisogna seguire questi passaggi:
    #Run
    #Open Run Dialog...
    #Argument tab
    #In VM arguments Section indicare:
    -Xmx512m

    La situazione è migliorata, sono riuscito a scrivere un'immagine JPEG dalle dimensioni di 6889x8098 px
    Direi che può bastare...

    Il problema cmq si è ripetuto con immagini di dimensioni superiori

    Grazie
    90's Commercial listener

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.