Skip to main content

[JAVA2D] drawPolyline()-setting stroke width

3 replies [Last post]
Anonymous

Hi,

I have an application that draws lines into a BufferedImage.
I would like to set the line width to 2, but it does not work.

The following is a code snipet. Assume bufferedImage is a
BufferedImage with an IndexedColorModel and there is a
AffineTransform object tx.

Graphics2D g2 = bufferedImage.createGraphics();

AffineTransform savedTx = g2.getTransform();
g2.transform( tx );
g2.setPaint( color );
g2.setStroke( new BasicStroke( 2 ) );
g2.drawPolyline( x, y, nPts );
g2.setTransform( savedTx );

I looked on the java.sun.com web site and a number of people
have asked this question, but no one has responded.

I would appreciate any help you can give me. By the way I am
using Java 1.4.2.

Thanks,
Nancy DeLosa

===========================================================================
To unsubscribe, send email to listserv@java.sun.com and include in the body
of the message "signoff JAVA2D-INTEREST". For general help, send email to
listserv@java.sun.com and include in the body of the message "help".

Reply viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.
Nancy DeLosa

Thank you for the responses to my email.
It turns out that my stroke width was too small.
I needed to scale the stroke width by the scale factor
that was in my AffineTransform. It is working now.

Thanks again,
Nancy DeLosa

> X-Original-To: JAVA2D-INTEREST@JAVA.SUN.COM
> Delivered-To: JAVA2D-INTEREST@JAVA.SUN.COM
> MIME-Version: 1.0
> Content-MD5: PLn8KH7UJFebiyLMr8lbpA==
> Date: Thu, 14 Oct 2004 16:50:57 -0400
> From: Nancy DeLosa
> Subject: [JAVA2D] drawPolyline()-setting stroke width
> Comments: cc: JAVADEV@ll.mit.edu
> To: JAVA2D-INTEREST@JAVA.SUN.COM
>
> Hi,
>
> I have an application that draws lines into a BufferedImage.
> I would like to set the line width to 2, but it does not work.
>
> The following is a code snipet. Assume bufferedImage is a
> BufferedImage with an IndexedColorModel and there is a
> AffineTransform object tx.
>
> Graphics2D g2 = bufferedImage.createGraphics();
>
> AffineTransform savedTx = g2.getTransform();
> g2.transform( tx );
> g2.setPaint( color );
> g2.setStroke( new BasicStroke( 2 ) );
> g2.drawPolyline( x, y, nPts );
> g2.setTransform( savedTx );
>
> I looked on the java.sun.com web site and a number of people
> have asked this question, but no one has responded.
>
> I would appreciate any help you can give me. By the way I am
> using Java 1.4.2.
>
> Thanks,
> Nancy DeLosa
>
> ===========================================================================
> To unsubscribe, send email to listserv@java.sun.com and include in the body
> of the message "signoff JAVA2D-INTEREST". For general help, send email to
> listserv@java.sun.com and include in the body of the message "help".

===========================================================================
To unsubscribe, send email to listserv@java.sun.com and include in the body
of the message "signoff JAVA2D-INTEREST". For general help, send email to
listserv@java.sun.com and include in the body of the message "help".

Jim Graham

Hi Nancy,

The issue you encountered here is related to bug report #4114921 which
asks for a way to scale coordinates independently of things like the
line width. This isn't really a bug since the current system scales
both together "by design", but we could potentially add new
capabilities to make this easier in the future. Meanwhile, the bug
report may give you some added perspective on the issue...

...jim

--On 10/15/04 11:19:32 AM -0400 Nancy DeLosa wrote:
> Thank you for the responses to my email.
> It turns out that my stroke width was too small.
> I needed to scale the stroke width by the scale factor
> that was in my AffineTransform. It is working now.
>
> Thanks again,
> Nancy DeLosa
>
>> Date: Thu, 14 Oct 2004 16:50:57 -0400
>> From: Nancy DeLosa
>> Subject: [JAVA2D] drawPolyline()-setting stroke width
>> To: JAVA2D-INTEREST@JAVA.SUN.COM
>>
>> Hi,
>>
>> I have an application that draws lines into a BufferedImage.
>> I would like to set the line width to 2, but it does not work.
>>
>> The following is a code snipet. Assume bufferedImage is a
>> BufferedImage with an IndexedColorModel and there is a
>> AffineTransform object tx.
>>
>> Graphics2D g2 = bufferedImage.createGraphics();
>>
>> AffineTransform savedTx = g2.getTransform();
>> g2.transform( tx );
>> g2.setPaint( color );
>> g2.setStroke( new BasicStroke( 2 ) );
>> g2.drawPolyline( x, y, nPts );
>> g2.setTransform( savedTx );
>>
>> I looked on the java.sun.com web site and a number of people
>> have asked this question, but no one has responded.
>>
>> I would appreciate any help you can give me. By the way I am
>> using Java 1.4.2.
>>
>> Thanks,
>> Nancy DeLosa

===========================================================================
To unsubscribe, send email to listserv@java.sun.com and include in the body
of the message "signoff JAVA2D-INTEREST". For general help, send email to
listserv@java.sun.com and include in the body of the message "help".

Jim Graham

It's hard to know what is going on here without knowing what the transform
is at the time of the drawPolyline call since the line width is relative to
the current transform. Do you have an isolated standalone test case for
this?

...jim

--On Thursday, October 14, 2004 4:50 PM -0400 Nancy DeLosa
wrote:

> Hi,
>
> I have an application that draws lines into a BufferedImage.
> I would like to set the line width to 2, but it does not work.
>
> The following is a code snipet. Assume bufferedImage is a
> BufferedImage with an IndexedColorModel and there is a
> AffineTransform object tx.
>
> Graphics2D g2 = bufferedImage.createGraphics();
>
> AffineTransform savedTx = g2.getTransform();
> g2.transform( tx );
> g2.setPaint( color );
> g2.setStroke( new BasicStroke( 2 ) );
> g2.drawPolyline( x, y, nPts );
> g2.setTransform( savedTx );
>
> I looked on the java.sun.com web site and a number of people
> have asked this question, but no one has responded.
>
> I would appreciate any help you can give me. By the way I am
> using Java 1.4.2.
>
> Thanks,
> Nancy DeLosa
>
> =========================================================================
> == To unsubscribe, send email to listserv@java.sun.com and include in the
> body of the message "signoff JAVA2D-INTEREST". For general help, send
> email to listserv@java.sun.com and include in the body of the message
> "help".

===========================================================================
To unsubscribe, send email to listserv@java.sun.com and include in the body
of the message "signoff JAVA2D-INTEREST". For general help, send email to
listserv@java.sun.com and include in the body of the message "help".