Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » GEF » draw2DCan figures of logic be added a Image without distortion?
draw2DCan figures of logic be added a Image without distortion? [message #161816] Fri, 17 December 2004 04:20 Go to next message
Eclipse UserFriend
Originally posted by: denghaitao.jctx.com

Hi all:
I have added a Image in the figure in logic .And I want to change the
size of the Image when I change the size of DDFigure, but when changed the
DDFFigure's size ,the Image becomes distortion.How can I do to avoid it?

thanks

the programs as follows:

public class DDFFigure extends NodeFigure implements HandleBounds {
........
protected void paintFigure(Graphics g) {
Rectangle r = getBounds().getCopy();

g.translate(r.getLocation());

g.setBackgroundColor(LogicColorConstants.blue);
g.setForegroundColor(LogicColorConstants.connectorGreen);
g.fillRectangle(0, 0, r.width, r.height);
int right = r.width - 1;
g.drawLine(0, Y1, right, Y1);
g.drawLine(0, Y1, 0, Y2);
g.setForegroundColor(LogicColorConstants.connectorGreen);
g.drawLine(0, Y2, right, Y2);
g.drawLine(right, Y1, right, Y2);
g.setForegroundColor(LogicColorConstants.connectorGreen);
g.setBackgroundColor(LogicColorConstants.connectorGreen);
topConnector.translate(0, 5);
g.fillPolygon(rightConnector);
g.drawPolygon(rightConnector);
g.fillPolygon(leftConnector);
g.drawPolygon(leftConnector);
g.fillPolygon(topConnector);
g.drawPolygon(topConnector);
g.fillPolygon(downConnector);
g.drawPolygon(downConnector);
g.setFont(DISPLAY_FONT);
g.setForegroundColor(DISPLAY_TEXT);
g.drawText("DDF", 8, 6);

Image image = new Image(null, LogicEditor.class
.getResourceAsStream("icons/model/toponode16.gif"));
int x = getBounds().getCopy().width;
int y = getBounds().getCopy().height;
//when Rectangle's size changed ,the image becomes distortion,how
can I do ?
g.drawImage(image,0, 0, image.getBounds().width,
image.getBounds().height,
0, 0, x, y);

topConnector.translate(0, -5);
}
Re: draw2DCan figures of logic be added a Image without distortion? [message #161838 is a reply to message #161816] Fri, 17 December 2004 05:05 Go to previous messageGo to next message
Pratik Shah is currently offline Pratik ShahFriend
Messages: 1077
Registered: July 2009
Senior Member
If you maintain the aspect ratio, it won't distort. Otherwise there's no
way to scale the image by different amounts in different directions and
still have it not distort, is there?

"Jesse" <denghaitao@jctx.com> wrote in message
news:cptmtn$boa$1@www.eclipse.org...
> Hi all:
> I have added a Image in the figure in logic .And I want to change the
> size of the Image when I change the size of DDFigure, but when changed the
> DDFFigure's size ,the Image becomes distortion.How can I do to avoid it?
>
> thanks
>
> the programs as follows:
>
> public class DDFFigure extends NodeFigure implements HandleBounds {
> ........
> protected void paintFigure(Graphics g) {
> Rectangle r = getBounds().getCopy();
>
> g.translate(r.getLocation());
>
> g.setBackgroundColor(LogicColorConstants.blue);
> g.setForegroundColor(LogicColorConstants.connectorGreen);
> g.fillRectangle(0, 0, r.width, r.height);
> int right = r.width - 1;
> g.drawLine(0, Y1, right, Y1);
> g.drawLine(0, Y1, 0, Y2);
> g.setForegroundColor(LogicColorConstants.connectorGreen);
> g.drawLine(0, Y2, right, Y2);
> g.drawLine(right, Y1, right, Y2);
> g.setForegroundColor(LogicColorConstants.connectorGreen);
> g.setBackgroundColor(LogicColorConstants.connectorGreen);
> topConnector.translate(0, 5);
> g.fillPolygon(rightConnector);
> g.drawPolygon(rightConnector);
> g.fillPolygon(leftConnector);
> g.drawPolygon(leftConnector);
> g.fillPolygon(topConnector);
> g.drawPolygon(topConnector);
> g.fillPolygon(downConnector);
> g.drawPolygon(downConnector);
> g.setFont(DISPLAY_FONT);
> g.setForegroundColor(DISPLAY_TEXT);
> g.drawText("DDF", 8, 6);
>
> Image image = new Image(null, LogicEditor.class
> .getResourceAsStream("icons/model/toponode16.gif"));
> int x = getBounds().getCopy().width;
> int y = getBounds().getCopy().height;
> //when Rectangle's size changed ,the image becomes distortion,how
> can I do ?
> g.drawImage(image,0, 0, image.getBounds().width,
> image.getBounds().height,
> 0, 0, x, y);
>
> topConnector.translate(0, -5);
> }
>
>
>
>
Re: draw2DCan figures of logic be added a Image without distortion? [message #161875 is a reply to message #161838] Fri, 17 December 2004 07:05 Go to previous messageGo to next message
Eclipse UserFriend
Originally posted by: denghaitao.jctx.com

Thanks for your answer.But how can I maintain the aspect ratio in this
program
Re: draw2DCan figures of logic be added a Image without distortion? [message #161907 is a reply to message #161816] Fri, 17 December 2004 14:59 Go to previous message
Eclipse UserFriend
Originally posted by: none.us.ibm.com

What do you mean by distorted? SWT only offers us one way to scale an
Image. The algorithm uses nearest-neighbor scaling I think, and not linear
interpolation a.k.a. "re-sampling" the image.

"Jesse" <denghaitao@jctx.com> wrote in message
news:cptmtn$boa$1@www.eclipse.org...
> Hi all:
> I have added a Image in the figure in logic .And I want to change the
> size of the Image when I change the size of DDFigure, but when changed the
> DDFFigure's size ,the Image becomes distortion.How can I do to avoid it?
>
> thanks
>
> the programs as follows:
>
> public class DDFFigure extends NodeFigure implements HandleBounds {
> ........
> protected void paintFigure(Graphics g) {
> Rectangle r = getBounds().getCopy();
>
> g.translate(r.getLocation());
>
> g.setBackgroundColor(LogicColorConstants.blue);
> g.setForegroundColor(LogicColorConstants.connectorGreen);
> g.fillRectangle(0, 0, r.width, r.height);
> int right = r.width - 1;
> g.drawLine(0, Y1, right, Y1);
> g.drawLine(0, Y1, 0, Y2);
> g.setForegroundColor(LogicColorConstants.connectorGreen);
> g.drawLine(0, Y2, right, Y2);
> g.drawLine(right, Y1, right, Y2);
> g.setForegroundColor(LogicColorConstants.connectorGreen);
> g.setBackgroundColor(LogicColorConstants.connectorGreen);
> topConnector.translate(0, 5);
> g.fillPolygon(rightConnector);
> g.drawPolygon(rightConnector);
> g.fillPolygon(leftConnector);
> g.drawPolygon(leftConnector);
> g.fillPolygon(topConnector);
> g.drawPolygon(topConnector);
> g.fillPolygon(downConnector);
> g.drawPolygon(downConnector);
> g.setFont(DISPLAY_FONT);
> g.setForegroundColor(DISPLAY_TEXT);
> g.drawText("DDF", 8, 6);
>
> Image image = new Image(null, LogicEditor.class
> .getResourceAsStream("icons/model/toponode16.gif"));
> int x = getBounds().getCopy().width;
> int y = getBounds().getCopy().height;
> //when Rectangle's size changed ,the image becomes distortion,how
> can I do ?
> g.drawImage(image,0, 0, image.getBounds().width,
> image.getBounds().height,
> 0, 0, x, y);
>
> topConnector.translate(0, -5);
> }
>
>
>
>
Previous Topic:Moving figure notification when done.
Next Topic:GEF & SWT
Goto Forum:
  


Current Time: Tue Apr 23 16:56:56 GMT 2024

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

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

Back to the top