Skip to main content

graphics and ints

3 replies [Last post]
andries_demont
Offline
Joined: 2006-10-26
Points: 0

Hi,

I'm trying to build a scalable image. When I interactively enlarge my icon, some discrete 'jumps' happen.

e.g when the line width is 3.4 or 3.5. In the first case I have to give a 3 and in the last case a 4 to the graphics object. So when I enlarge my icon, suddonly the line width becomes 25 percent thicker. Is there a way to smoothen this?

The same thing happens with the shapes. This is even a much bigger problem. However the cause is the same: integers. Even when I use shapes (and doubles) instead of drawRectangle or drawPolygon... in Graphics2D, the icons remains to have sudden 'jumps' as I scale them.

It is essential that the computing time is as low as possible.

Does anyone has some ideas?

Message was edited by: andries_demont

Reply viewing options

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

Hi Andries,

Have you tried enabling antialiasing? Without that, there's no way
to have a smooth transition between integral line widths (after all,
you can't fill fractional parts of pixels). With antialiasing, you
can at least trick the eye into thinking that there are fractional
line widths. Enabling antialising may be a reasonable solution for
larger icon sizes, but you may not like it for smaller sizes (like
16x16); typically icon designers are pretty fussy about the placement
of each pixel at small sizes, and antialiasing at those small sizes
may make the icon look "fuzzy". You could consider using
antialiasing for certain size (like the example you mention where
line widths are non-integral), but leave it disabled for smaller
sizes where you want/need more control.

Hope this helps,
Chris

On Nov 3, 2006, at 3:14 AM, java2d@javadesktop.org wrote:
> Hi,
>
> I'm trying to build a scalable image. When I interactively enlarge
> my icon, some discrete 'jumps' happen.
>
> e.g when the line width is 3.4 or 3.5. In the first case I have to
> give a 3 and in the last case a 4 to the graphics object. So when I
> enlarge my icon, suddonly the line width becomes 25 percent
> thicker. Is there a way to smoothen this?
>
> The same thing happens with the shapes. This is even a much bigger
> problem. However the cause is the same: integers. Even when I use
> shapes (and doubles) instead of drawRectangle or drawPolygon... in
> Graphics2D, the icons remains to have sudden 'jumps' as I scale them.
>
> Does anyone has some ideas?
> [Message sent by forum member 'andries_demont' (andries_demont)]
>
> http://forums.java.net/jive/thread.jspa?messageID=170058
>
> ======================================================================
> =====
> 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".

andries_demont
Offline
Joined: 2006-10-26
Points: 0

Hi Chris,

I did try antialiasing. And it is good enough on large scale just as you said. However the images will be used on a scale from 20 x 20 or 40 x 40.

I was hoping i could give the line_width as a double in my stroke. And let graphics do something 'reasonable' with it when antialiasing is activated.

I have no clue how I could have more control at this moment. Maybe I have to write wrappers around some classes.

Thanks for the response.

andries_demont
Offline
Joined: 2006-10-26
Points: 0

I was able to solve the issues.

The stroke issue was easy: you have to make sure you enter a float in the stroke. (I used an int)

The other issue was fixed by placing the transform on the graphics and not on the shapes. This way everything is drawn a lot better. In the past my shapes 'moved' independently from each other. By placing the transform on the graphics this effect is almost completely neutralised.