Canvas restore underflow after image export

TeeChart for Java (NetBeans, Eclipse, Android Studio, etc)
Post Reply
znakeeye
Newbie
Newbie
Posts: 44
Joined: Mon Jan 07, 2013 12:00 am

Canvas restore underflow after image export

Post by znakeeye » Sat Mar 16, 2013 10:27 pm

I do this to export an image from my area chart (painted with SeriesBand):

Code: Select all

chart.doInvalidate();
Image img = chart.getExport().getImage().image(WIDTH, HEIGHT);
chart.doInvalidate();
That works the first time. The second time it crashes on the call to restore() in Graphics3DAndroid.java.

Code: Select all

public void unClip() {
		canvas.restore();
		//canvas.clipRect(0, 0, bounds.width, bounds.height,  android.graphics.Region.Op.INTERSECT);
	}
java.lang.IllegalStateException: Underflow in restore

Why do I end up in an erroneous state? Sure looks like a bug!

znakeeye
Newbie
Newbie
Posts: 44
Joined: Mon Jan 07, 2013 12:00 am

Re: Canvas restore underflow after image export

Post by znakeeye » Sat Mar 16, 2013 10:58 pm

Please post a source code fix here as soon as possible. This is a blocker for my app :(
I'll see if I can fix it until then! Thanks.

znakeeye
Newbie
Newbie
Posts: 44
Joined: Mon Jan 07, 2013 12:00 am

Re: Canvas restore underflow after image export

Post by znakeeye » Sat Mar 16, 2013 11:14 pm

Ok, found a fix. Please verify that this is the right way to solve this!

Code: Select all

public Image image(int width, int height) {
		final Object old = androidGraphics.getGraphics();
		Image i = new Image(width, height);
		Canvas c = new Canvas(i.bitmap);
		
		// FIX: Explicitly call save() to allow for canvas.restore() later on.
		c.save();

Yeray
Site Admin
Site Admin
Posts: 9613
Joined: Tue Dec 05, 2006 12:00 am
Location: Girona, Catalonia
Contact:

Re: Canvas restore underflow after image export

Post by Yeray » Tue Mar 19, 2013 11:38 am

znakeeye wrote:I do this to export an image from my area chart (painted with SeriesBand):

Code: Select all

chart.doInvalidate();
Image img = chart.getExport().getImage().image(WIDTH, HEIGHT);
chart.doInvalidate();
That works the first time. The second time it crashes on the call to restore() in Graphics3DAndroid.java.

Code: Select all

public void unClip() {
		canvas.restore();
		//canvas.clipRect(0, 0, bounds.width, bounds.height,  android.graphics.Region.Op.INTERSECT);
	}
java.lang.IllegalStateException: Underflow in restore

Why do I end up in an erroneous state? Sure looks like a bug!
I'm not able to reproduce it in an Android 4.2 emulator.
Could you please attach a simple example project we can run as-is to reproduce the problem here?
Thanks in advance.
Best Regards,
ImageYeray Alonso
Development & Support
Steema Software
Av. Montilivi 33, 17003 Girona, Catalonia (SP)
Image Image Image Image Image Image Please read our Bug Fixing Policy

Post Reply