Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » Standard Widget Toolkit (SWT) » How can I make "Image" manually transparent?
How can I make "Image" manually transparent? [message #460659] Fri, 02 September 2005 17:51 Go to next message
Eclipse UserFriend
Originally posted by: gerold.meisinger-reg.gmx.at

I want to write a drawing programme with layers. The workspace of the
application is a "Canvas" which consists of two "Image" objects:
passiveGround (background color, grid etc.) and activeGround (drawings
etc.).
I store them seperatly, because the passiveGround takes very long to
redraw and it should only redraw itself, if a application property has
changed. activeGround should redraw everytime the user draws something.
The workspace should now layer activeGround on passiveGround, so both are
partly visibile.

My problem is, that I don't know how to make transparent "Image" objects.
I can't load a transparent image file (GIF, PNG), because the image is
drawn during runtime. I just need a method to define a color as
transparent.


The code looks something like this:

public class Application
extends Canvas
{
Image passiveGround, activeGround;

...

public void updatePassiveGround()
{
passiveGround = new Image( getDisplay(), getBounds());
GC gcPassive = new GC( passiveGround);

gcPassive.draw... // some drawing routines

gcPassive.dispose();
}

public void updatePassiveGround()
{
Image activeGround = new Image( getDisplay(), getBounds());
GC gcActive = new GC( activeGround);

gcActive.draw... // some drawing routines

gcActive.dispose();
}

class MyPaintListener
implements PaintLister
{
public void paintControl( PaintEvent paintEvent)
{
GC gc = paintEvent.gc;

gc.drawImage( passiveGround, 0, 0);
gc.drawImage( activeGround, 0, 0);
}
}
}
Reformatted code [message #460660 is a reply to message #460659] Fri, 02 September 2005 17:54 Go to previous messageGo to next message
Eclipse UserFriend
Originally posted by: gerold.meisinger-reg.gmx.at

public class Application
extends Canvas
{
Image passiveGround, activeGround;

...

public void updatePassiveGround()
{
passiveGround = new Image( getDisplay(), getBounds());
GC gcPassive = new GC( passiveGround);

gcPassive.draw... // some drawing routines

gcPassive.dispose();
}

public void updatePassiveGround()
{
Image activeGround = new Image( getDisplay(), getBounds());
GC gcActive = new GC( activeGround);

gcActive.draw... // some drawing routines

gcActive.dispose();
}

class MyPaintListener
implements PaintLister
{
public void paintControl( PaintEvent paintEvent)
{
GC gc = paintEvent.gc;

gc.drawImage( passiveGround, 0, 0);
gc.drawImage( activeGround, 0, 0);
}
}
}
Re: How can I make "Image" manually transparent? [message #460661 is a reply to message #460659] Fri, 02 September 2005 18:18 Go to previous message
Eclipse UserFriend
Originally posted by: sunil_kamath.nohotspammail.com

"Gerold Meisinger" <gerold.meisinger-reg@gmx.at> wrote in message
news:8a5775453ca24fdfd0f410a5005d70fc$1@www.eclipse.org...
>I want to write a drawing programme with layers. The workspace of the
>application is a "Canvas" which consists of two "Image" objects:
>passiveGround (background color, grid etc.) and activeGround (drawings
>etc.).
> I store them seperatly, because the passiveGround takes very long to
> redraw and it should only redraw itself, if a application property has
> changed. activeGround should redraw everytime the user draws something.
> The workspace should now layer activeGround on passiveGround, so both are
> partly visibile.
>
> My problem is, that I don't know how to make transparent "Image" objects.
> I can't load a transparent image file (GIF, PNG), because the image is
> drawn during runtime. I just need a method to define a color as
> transparent.
>
[snip]

If you are creating a drawing program, why don't you consider GEF?
It has already provides the functionality you need.
---
Sunil
Previous Topic:Off-screen Shell or Display?
Next Topic:Scrollbar problem! very similar to another post "2 trees in sync "
Goto Forum:
  


Current Time: Mon Jun 17 01:40:54 GMT 2019

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

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

Back to the top