Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

How do you maximize a figure upon creation?

9 views
Skip to first unread message

Jesse

unread,
Apr 26, 2010, 8:03:06 PM4/26/10
to

If I use code such as:
fig1 = figure(....);
...
saveas(fig1, 'myfilename.jpg');

The saved file can look terrible because the figure wasn't maximized prior to saving (if you save it after maximising yourself, then it looks fine).

Is there some way I can maximize the figure after creating it so that it saves properly?

Thanks,
Jesse

ImageAnalyst

unread,
Apr 26, 2010, 8:26:09 PM4/26/10
to
set(gcf, 'Position', get(0,'Screensize')); % Maximize figure.

Jesse

unread,
Apr 26, 2010, 10:36:05 PM4/26/10
to
ImageAnalyst <imagea...@mailinator.com> wrote in message <cd4efb1f-1040-4539...@b33g2000yqc.googlegroups.com>...

> set(gcf, 'Position', get(0,'Screensize')); % Maximize figure.

Thanks,
That seems to work. However, when I resize my figures (about a dozen of them) before saving, I end up getting a whole bunch of java exceptions which (kind of) crash matlab and definetely make the figures crash.

The problem seems to be that matlab can't keep up with the screen repaint due to the resizing.

The exceptions are:

Exception in thread "AWT-EventQueue-0" 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.createCompatibleWritableRaster(Unknown Source)
at sun.awt.image.SunVolatileImage.getBackupImage(Unknown Source)
at sun.awt.image.VolatileSurfaceManager.getBackupSurface(Unknown Source)
at sun.awt.image.VolatileSurfaceManager.initialize(Unknown Source)
at sun.awt.image.SunVolatileImage.<init>(Unknown Source)
at sun.awt.image.SunVolatileImage.<init>(Unknown Source)
at sun.awt.image.SunVolatileImage.<init>(Unknown Source)
at sun.awt.image.SunVolatileImage.<init>(Unknown Source)
at sun.awt.windows.WComponentPeer.createVolatileImage(Unknown Source)
at java.awt.Component.createVolatileImage(Unknown Source)
at java.awt.Component$BltBufferStrategy.createBackBuffers(Unknown Source)
at java.awt.Component$BltBufferStrategy.<init>(Unknown Source)
at java.awt.Component$BltSubRegionBufferStrategy.<init>(Unknown Source)
at java.awt.Component.createBufferStrategy(Unknown Source)
at java.awt.Window.createBufferStrategy(Unknown Source)
at javax.swing.BufferStrategyPaintManager$BufferInfo.createBufferStrategy(Unknown Source)
at javax.swing.BufferStrategyPaintManager$BufferInfo.createBufferStrategy(Unknown Source)
at javax.swing.BufferStrategyPaintManager$BufferInfo.getBufferStrategy(Unknown Source)
at javax.swing.BufferStrategyPaintManager.prepare(Unknown Source)
at javax.swing.BufferStrategyPaintManager.paint(Unknown Source)
at javax.swing.RepaintManager.paint(Unknown Source)
at javax.swing.JComponent.paint(Unknown Source)
at java.awt.GraphicsCallback$PaintCallback.run(Unknown Source)
at sun.awt.SunGraphicsCallback.runOneComponent(Unknown Source)
at sun.awt.SunGraphicsCallback.runComponents(Unknown Source)
at java.awt.Container.paint(Unknown Source)
at javax.swing.RepaintManager.paintDirtyRegions(Unknown Source)
at javax.swing.RepaintManager.paintDirtyRegions(Unknown Source)
at javax.swing.RepaintManager.seqPaintDirtyRegions(Unknown Source)
at javax.swing.SystemEventQueueUtilities$ComponentWorkRequest.run(Unknown Source)

Image Analyst

unread,
Apr 26, 2010, 10:45:22 PM4/26/10
to
Jesse
Sorry, I can't help you with that. The Mathworks might be able to.

TideMan

unread,
Apr 26, 2010, 10:54:18 PM4/26/10
to
On Apr 27, 2:36 pm, "Jesse " <jessepe...@gmail.com> wrote:
> ImageAnalyst <imageanal...@mailinator.com> wrote in message <cd4efb1f-1040-4539-9ba0-a54415db9...@b33g2000yqc.googlegroups.com>...

When I get stuff like this, it is usually because I have screwed
something up previously.
The best thing to do is to exit from Matlab and start again.
If it happens in a new Matlab session, there is a problem.............

Jinkui Zhu

unread,
Apr 27, 2010, 6:04:41 PM4/27/10
to

with 'print' function, you can specify the resolution of the figure
you save. maybe it will help.

Soumyabrata Dev

unread,
Oct 9, 2013, 3:14:06 AM10/9/13
to
I faced a similar Java error while saving a series of pictures. This can be solved if you do the following things in order: generate the figure, save the current figure window and then close the current figure window by the command "close gcf". On the execution of the new image, a different figure window is created, saved and subsequently closed. This cycle saves memory; and the script won't crash.
Hope it helps!
0 new messages