Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » Standard Widget Toolkit (SWT) » Performance Tipps for gc.drawImage() ?
Performance Tipps for gc.drawImage() ? [message #466725] Tue, 17 January 2006 01:48 Go to next message
Eclipse UserFriend
Originally posted by: yen-chia.lin.liwest.at

Hi,

I have a question.

How can i improve the performance from my SWT Shell with just a Canvas
in it?

I want to draw a image as Background Image for the window and then draw
some Text on it.

it looks like this:

public void paintControl(org.eclipse.swt.events.PaintEvent e) {
gc = e.gc;
gc.setFont(fontSWT);
gc.drawImage(backgroundImage, startingX, startingY);
.....
gc.drawText(text, x, y, true);
gc.drawText(text, x2, y2, true);
gc.drawText(text, x3, y3, true);
}

Thats it!

The size of the Shell and BackgroundImage are fix. They are NOT
resizable. And the backgroundImage is a *.png file.

So how can i set/draw a background image that is faster than the above
methods? ^^

tia,

Yen-chia
Re: Performance Tipps for gc.drawImage() ? [message #466805 is a reply to message #466725] Tue, 17 January 2006 19:39 Go to previous messageGo to next message
Steve Northover is currently offline Steve NorthoverFriend
Messages: 1636
Registered: July 2009
Senior Member
You can't. Please enter a bug report with the image and a stand alone
snippet so we can investigate. Thanks!

"Lin Yen-Chia" <yen-chia.lin@liwest.at> wrote in message
news:dqhi0c$4qf$1@utils.eclipse.org...
> Hi,
>
> I have a question.
>
> How can i improve the performance from my SWT Shell with just a Canvas
> in it?
>
> I want to draw a image as Background Image for the window and then draw
> some Text on it.
>
> it looks like this:
>
> public void paintControl(org.eclipse.swt.events.PaintEvent e) {
> gc = e.gc;
> gc.setFont(fontSWT);
> gc.drawImage(backgroundImage, startingX, startingY);
> .....
> gc.drawText(text, x, y, true);
> gc.drawText(text, x2, y2, true);
> gc.drawText(text, x3, y3, true);
> }
>
> Thats it!
>
> The size of the Shell and BackgroundImage are fix. They are NOT
> resizable. And the backgroundImage is a *.png file.
>
> So how can i set/draw a background image that is faster than the above
> methods? ^^
>
> tia,
>
> Yen-chia
Re: Performance Tipps for gc.drawImage() ? [message #466810 is a reply to message #466805] Tue, 17 January 2006 20:24 Go to previous messageGo to next message
Eclipse UserFriend
Originally posted by: yen-chia.lin.liwest.at

Steve Northover schrieb:
> You can't. Please enter a bug report with the image and a stand alone
> snippet so we can investigate. Thanks!
>

is there no way to draw a image in doublebuffered or something like that?

because my image is not going to change. the text is the only thing that
will change in the time.
Re: Performance Tipps for gc.drawImage() ? [message #466875 is a reply to message #466810] Wed, 18 January 2006 19:58 Go to previous messageGo to next message
Steve Northover is currently offline Steve NorthoverFriend
Messages: 1636
Registered: July 2009
Senior Member
I can't make any suggestions without the code.

"Lin Yen-Chia" <yen-chia.lin@liwest.at> wrote in message
news:dqjjd3$e5n$1@utils.eclipse.org...
> Steve Northover schrieb:
> > You can't. Please enter a bug report with the image and a stand alone
> > snippet so we can investigate. Thanks!
> >
>
> is there no way to draw a image in doublebuffered or something like that?
>
> because my image is not going to change. the text is the only thing that
> will change in the time.
Re: Performance Tipps for gc.drawImage() ? [message #466895 is a reply to message #466725] Thu, 19 January 2006 00:56 Go to previous messageGo to next message
Adam Kumpf is currently offline Adam KumpfFriend
Messages: 14
Registered: July 2009
Junior Member
Lin Yen-Chia wrote:

> Hi,

> I have a question.

> How can i improve the performance from my SWT Shell with just a Canvas
> in it?

> I want to draw a image as Background Image for the window and then draw
> some Text on it.

> it looks like this:

> public void paintControl(org.eclipse.swt.events.PaintEvent e) {
> gc = e.gc;
> gc.setFont(fontSWT);
> gc.drawImage(backgroundImage, startingX, startingY);
> .....
> gc.drawText(text, x, y, true);
> gc.drawText(text, x2, y2, true);
> gc.drawText(text, x3, y3, true);
> }

> Thats it!

> The size of the Shell and BackgroundImage are fix. They are NOT
> resizable. And the backgroundImage is a *.png file.

> So how can i set/draw a background image that is faster than the above
> methods? ^^

> tia,

> Yen-chiaHi Yen-Chia,


I think I've run into something similar to this. What I did was to keep
track of some state of the canvas. only draw the background image once,
and then draw text and lines over the top of it.. but do not invalidate
it. however, when the text changes, that area of the canvas will need to
be redrawn. Try to figure out which area is "dirty" and then only repaint
your image in that region instead of the entire canvas.

I'm still a little new with SWT, so I hope that helps a bit..but I may be
way off.

Best Regards,
Adam
Re: Performance Tipps for gc.drawImage() ? [message #466897 is a reply to message #466895] Thu, 19 January 2006 02:14 Go to previous message
Adam Kumpf is currently offline Adam KumpfFriend
Messages: 14
Registered: July 2009
Junior Member
Adam Kumpf wrote:

> Lin Yen-Chia wrote:

>> Hi,

>> I have a question.

>> How can i improve the performance from my SWT Shell with just a Canvas
>> in it?

>> I want to draw a image as Background Image for the window and then draw
>> some Text on it.

>> it looks like this:

>> public void paintControl(org.eclipse.swt.events.PaintEvent e) {
>> gc = e.gc;
>> gc.setFont(fontSWT);
>> gc.drawImage(backgroundImage, startingX, startingY);
>> .....
>> gc.drawText(text, x, y, true);
>> gc.drawText(text, x2, y2, true);
>> gc.drawText(text, x3, y3, true);
>> }

>> Thats it!

>> The size of the Shell and BackgroundImage are fix. They are NOT
>> resizable. And the backgroundImage is a *.png file.

>> So how can i set/draw a background image that is faster than the above
>> methods? ^^

>> tia,

>> Yen-chiaHi Yen-Chia,


> I think I've run into something similar to this. What I did was to keep
> track of some state of the canvas. only draw the background image once,
> and then draw text and lines over the top of it.. but do not invalidate
> it. however, when the text changes, that area of the canvas will need to
> be redrawn. Try to figure out which area is "dirty" and then only repaint
> your image in that region instead of the entire canvas.

> I'm still a little new with SWT, so I hope that helps a bit..but I may be
> way off.

> Best Regards,
> Adamoh, a couple more suggestions while I'm thinking about it...

I found that setting the GC to "Advanced" before you draw the background
image really slows things down a lot! (Advanced turns on Anti-aliasing,
and some other stuff too).

I also found that loading the image from the file is quite expensive in
terms of time. Make sure you only load the image from the file once, then
re-use that image when you need to redraw.

hope that helps a bit.

Best Regards,
Adam
kumpf@mit.edu
Previous Topic:Dialog to Load Images?
Next Topic:SWT Group with no title -- can I make the background color consistent?
Goto Forum:
  


Current Time: Fri Dec 27 01:00:31 GMT 2024

Powered by FUDForum. Page generated in 0.03678 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top