On Mon, 14 Mar 2022 01:47:20 GMT, Alexander Zuev <kiz...@openjdk.org> wrote:

>> src/java.desktop/share/classes/javax/swing/ImageIcon.java line 463:
>> 
>>> 461:         if (hintChanged) {
>>> 462:             ((Graphics2D) 
>>> g).setRenderingHint(RenderingHints.KEY_INTERPOLATION,
>>> 463:                     oldHint == null ? 
>>> RenderingHints.VALUE_INTERPOLATION_NEAREST_NEIGHBOR : oldHint);
>> 
>> This might be a rookie question:
>> 
>> When it comes to modifying and restoring a Graphics, I've seen two common 
>> patterns:
>> A. Call `newG = g.create()` and later `newG.dispose()`
>> B. Call `g.setX(newValue)` and then call `g.setX(oldValue)` later
>> 
>> Is there guidance on when to use which? Or is one always preferred?
>
>> This might be a rookie question:
>> 
>> When it comes to modifying and restoring a Graphics, I've seen two common 
>> patterns: A. Call `newG = g.create()` and later `newG.dispose()` B. Call 
>> `g.setX(newValue)` and then call `g.setX(oldValue)` later
>> 
>> Is there guidance on when to use which? Or is one always preferred?
> 
> Usually i follow the rule of minimal action. When i need to set a lot of 
> hints that needs to be later unrolled such as changing graphics coordinates 
> and such - i'm creating a new Graphics. When i only need to manipulate a 
> single hint and it can easily be unrolled - i am using the same object. In 
> this case i'm changing just a single hint.

I am not sure that this is the right place to change the hints.
If we want to always scale the icon using the bicubic interpolation then it is 
better to do it where we call the paintIcon() method in some jcomponent(this 
probably may be configured by some option - similar to the text antialisaing). 
But it will affect performance since the bicubic is much slower.

But before discussing this shared code change could you please provide some 
info on why it worked fine before? Why we try to downscale the image and do not 
get an exact size from the native.

-------------

PR: https://git.openjdk.java.net/jdk/pull/7805

Reply via email to