How can I make "Image" manually transparent? [message #460659] |
Fri, 02 September 2005 17:51 |
Eclipse User |
|
|
|
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 |
Eclipse User |
|
|
|
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 |
Eclipse User |
|
|
|
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
|
|
|
Powered by
FUDForum. Page generated in 0.04893 seconds