Skip to main content

[JAVA2D] zooming & double buffering

4 replies [Last post]
Anonymous

Reply viewing options

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

hi jim,
sorry, i don't understand what i must do that my application work. can
you show it to me in my example? has it woked for you?
greetings michael

Jim Graham schrieb am 15.02.2004 13:22:

> Hi Michael,
>
> Yes, I guess you do apply *a* transform to *a* graphics object before
> you get to the code that draws the text, but it's the wrong graphics
> object that you apply the scale to.
>
> You are scaling the graphics object that is passed to your paint
> method - the one that you subsequently hand off to your children.
> But, the only thing that graphics object is used for when your
> code is run in its default "buffered" mode is to execute a call to
> drawImage - thus the only thing it gets a chance to scale are the
> pixels that have been put into that BufferedImage. But the pixels
> you placed in that BufferedImage were placed there by a different
> Graphics object (called "bufferedGraphics" in your example code).
> This "bufferedGraphics" object never has a scale applied to it so
> it is rendering the text at a default 1:1 coordinate mapping.
>
> The net result is that the BufferedImage ends up containing pixels
> representing unzoomed text and you render the pixels of that
> BufferedImage to the screen via a zoomed (i.e. scaled) Graphics
> object - thus you get "pixelated" zooming.
>
> What Phil and Emmanuel have been trying to tell you is that you need
> to have applied a scale to the same graphics object that you execute
> the "drawString" call on in order to have the text scaled smoothly.
> You need to draw the text into the BufferedImage using a graphics
> object that has a zoom applied to it and then copy it to the output
> graphics with the default (unzoomed) transform.
>
> ...jim
>
> --On Thursday, February 12, 2004 9:23 AM +0100 Michael Seele
> wrote:
>
>> please look at my example! i scale the affine transform *before *i
>> call drawText...
>>
>> Emmanuel Pietriga schrieb am 12.02.2004 08:36:
>>
>>> I think there is a misunderstanding here. You have to apply the
>>> scaling affine transform *before* calling drawing primitives such as
>>> drawText. If you call it *after* the rendering has been done, i.e.
>>> on the rendered buffered image, you're doing image scaling on image
>>> pixels as Phil Race said, and there is no way you can get good font
>>> rendering with this method (unless, maybe, if you do some
>>> antialiasing, but it would not be that good, and would fail with
>>> large zooming factors).
>>>
>>> Emmanuel
>>>
>>>
>>> Michael Seele wrote:
>>>
>>>> thats right. but theres no change when i re-render my image on every
>>>> zoom change. please look at my example!
>>>>
>>>> Phil Race schrieb am 11.02.2004 16:29:
>>>>
>>>>> Michael Seele wrote:
>>>>>
>>>>>> hi guys,
>>>>>> i have a big problem:
>>>>>> my application shows lot of rectangles which can be dragged on the
>>>>>> screen. the application also supports zooming, i implement this
>>>>>> with transform scale. is it possible to use double buffering to
>>>>>> draw the rectangles(they contains lot of text). when i use the
>>>>>> standart bufferedImage, the text looks not very good. for example
>>>>>> i add two screenshoots. one in 100% and one in 400%!!!
>>>>>> thanks
>>>>>
>>>>>
>>>>>
>>>>>
>>>>>
>>>>> its not just fonts, its everything. look at the tick marks too.
>>>>> You will need to change your approach.
>>>>> In your case when you scale there's no text drawing happening.
>>>>> Its just image scaling on image pixels.
>>>>> ie you are pre-rendering an image at one resolution and then
>>>>> scaling the image pixels to other resolutions.
>>>>> That is not how to do resolution independent graphics.
>>>>>
>>>>> You will need to re-render eveything at the requested resolution
>>>>> each time.
>>>>>
>>>>> -phil.
>>>>>
>>>>> ==================================================================
>>>>> =========
>>>>>
>>>>>
>>>>>
>>>>> 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".
>>>>>
>>>>
>>>> --
>>>> Mit freundlichen Gruessen
>>>> Michael Seele(Michael.Seele@guh-software.de)
>>>>
>>>> G & H Softwareentwicklung GmbH Tel.: {+49|0} 7451 - 53 706 0
>>>> Robert-Bosch-Str. 23 Fax: {+49|0} 7451 - 53 706 90
>>>> D-72160 Horb a.N. http://www.guh-software.de
>>>>
>>>>
>>>> ===================================================================
>>>> ========
>>>>
>>>> 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".
>>>
>>>
>>>
>>>
>>> --
>>> Emmanuel Pietriga (epietriga@nuxeo.com)
>>> tel (mobile): +33 6 88 51 94 98
>>> http://claribole.net
>>>
>>> ====================================================================
>>> =======
>>>
>>> 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".
>
>
> ===========================================================================
>
> 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

> sorry, i don't understand what i must do that my application work. can
> you show it to me in my example? has it woked for you?
> greetings michael

All of the tips and tricks involved in doing a proper zoomable GUI
make the subject far too involved for a forum like this.

You really should look into one of the packages that people have
been mentioning here in their responses to you...

...jim

===========================================================================
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 Michael,

Yes, I guess you do apply *a* transform to *a* graphics object before
you get to the code that draws the text, but it's the wrong graphics
object that you apply the scale to.

You are scaling the graphics object that is passed to your paint
method - the one that you subsequently hand off to your children.
But, the only thing that graphics object is used for when your
code is run in its default "buffered" mode is to execute a call to
drawImage - thus the only thing it gets a chance to scale are the
pixels that have been put into that BufferedImage. But the pixels
you placed in that BufferedImage were placed there by a different
Graphics object (called "bufferedGraphics" in your example code).
This "bufferedGraphics" object never has a scale applied to it so
it is rendering the text at a default 1:1 coordinate mapping.

The net result is that the BufferedImage ends up containing pixels
representing unzoomed text and you render the pixels of that
BufferedImage to the screen via a zoomed (i.e. scaled) Graphics
object - thus you get "pixelated" zooming.

What Phil and Emmanuel have been trying to tell you is that you need
to have applied a scale to the same graphics object that you execute
the "drawString" call on in order to have the text scaled smoothly.
You need to draw the text into the BufferedImage using a graphics
object that has a zoom applied to it and then copy it to the output
graphics with the default (unzoomed) transform.

...jim

--On Thursday, February 12, 2004 9:23 AM +0100 Michael Seele
wrote:

> please look at my example! i scale the affine transform *before *i
> call drawText...
>
> Emmanuel Pietriga schrieb am 12.02.2004 08:36:
>
>> I think there is a misunderstanding here. You have to apply the
>> scaling affine transform *before* calling drawing primitives such as
>> drawText. If you call it *after* the rendering has been done, i.e.
>> on the rendered buffered image, you're doing image scaling on image
>> pixels as Phil Race said, and there is no way you can get good font
>> rendering with this method (unless, maybe, if you do some
>> antialiasing, but it would not be that good, and would fail with
>> large zooming factors).
>>
>> Emmanuel
>>
>>
>> Michael Seele wrote:
>>
>>> thats right. but theres no change when i re-render my image on every
>>> zoom change. please look at my example!
>>>
>>> Phil Race schrieb am 11.02.2004 16:29:
>>>
>>>> Michael Seele wrote:
>>>>
>>>>> hi guys,
>>>>> i have a big problem:
>>>>> my application shows lot of rectangles which can be dragged on the
>>>>> screen. the application also supports zooming, i implement this
>>>>> with transform scale. is it possible to use double buffering to
>>>>> draw the rectangles(they contains lot of text). when i use the
>>>>> standart bufferedImage, the text looks not very good. for example
>>>>> i add two screenshoots. one in 100% and one in 400%!!!
>>>>> thanks
>>>>
>>>>
>>>>
>>>>
>>>> its not just fonts, its everything. look at the tick marks too.
>>>> You will need to change your approach.
>>>> In your case when you scale there's no text drawing happening.
>>>> Its just image scaling on image pixels.
>>>> ie you are pre-rendering an image at one resolution and then
>>>> scaling the image pixels to other resolutions.
>>>> That is not how to do resolution independent graphics.
>>>>
>>>> You will need to re-render eveything at the requested resolution
>>>> each time.
>>>>
>>>> -phil.
>>>>
>>>> ==================================================================
>>>> =========
>>>>
>>>>
>>>>
>>>> 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".
>>>>
>>>
>>> --
>>> Mit freundlichen Gruessen
>>> Michael Seele(Michael.Seele@guh-software.de)
>>>
>>> G & H Softwareentwicklung GmbH Tel.: {+49|0} 7451 - 53 706 0
>>> Robert-Bosch-Str. 23 Fax: {+49|0} 7451 - 53 706 90
>>> D-72160 Horb a.N. http://www.guh-software.de
>>>
>>>
>>> ===================================================================
>>> ========
>>>
>>> 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".
>>
>>
>>
>> --
>> Emmanuel Pietriga (epietriga@nuxeo.com)
>> tel (mobile): +33 6 88 51 94 98
>> http://claribole.net
>>
>> ====================================================================
>> =======
>>
>> 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".

===========================================================================
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".

Emmanuel Pietriga

Michael is right. Anyway, coding a ZUI is not the easiest thing to do
especially if you want to do it right from A to Z. Unless you really
have time to code it yourself, or unless you have very specific problems
to deal with that are not addressed by existing ZUI toolkits, I would
strongly recommend using one of the existing open source libraries for
providing a zooming framework to you application, no matter whether it
is ZVTM [1], Piccolo (formerly known as Jazz [2]) or anything else.

[1] http://zvtm.sourceforge.net
[2] http://www.cs.umd.edu/hcil/jazz/

These will provide you with easy methods to manage your ZUI, taking care
of low-level graphics operation for you (applying appropriate affine
transforms on the right objects, doing specific clipping to enhance
performances, etc.). They are especially useful if your application is
not just a viewer but an editor.

Emmanuel

Jim Graham wrote:

> Hi Michael,
>
> Yes, I guess you do apply *a* transform to *a* graphics object before
> you get to the code that draws the text, but it's the wrong graphics
> object that you apply the scale to.
>
> You are scaling the graphics object that is passed to your paint
> method - the one that you subsequently hand off to your children.
> But, the only thing that graphics object is used for when your
> code is run in its default "buffered" mode is to execute a call to
> drawImage - thus the only thing it gets a chance to scale are the
> pixels that have been put into that BufferedImage. But the pixels
> you placed in that BufferedImage were placed there by a different
> Graphics object (called "bufferedGraphics" in your example code).
> This "bufferedGraphics" object never has a scale applied to it so
> it is rendering the text at a default 1:1 coordinate mapping.
>
> The net result is that the BufferedImage ends up containing pixels
> representing unzoomed text and you render the pixels of that
> BufferedImage to the screen via a zoomed (i.e. scaled) Graphics
> object - thus you get "pixelated" zooming.
>
> What Phil and Emmanuel have been trying to tell you is that you need
> to have applied a scale to the same graphics object that you execute
> the "drawString" call on in order to have the text scaled smoothly.
> You need to draw the text into the BufferedImage using a graphics
> object that has a zoom applied to it and then copy it to the output
> graphics with the default (unzoomed) transform.
>
> ...jim
>

--
Emmanuel Pietriga (epietriga@nuxeo.com)
tel (mobile): +33 6 88 51 94 98
http://claribole.net

===========================================================================
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".