Image scaling is very poor

817 views
Skip to first unread message

Andrew Hughes

unread,
Dec 22, 2009, 9:48:20 AM12/22/09
to jfxtr...@googlegroups.com
Hi Guys,

JavaFX image scaling appears to yield quite poor results. I'm wondering if there is a better way to do this?  If so I would certainly like to add this 'way' to JFXtra's. 

I've attached two png's (and hopefully the mailing list allows this). One at 100% and another resized in photoshop at 50%. You can clearly see that the 50% has lost some quality, but all the text is still legible. These kinda results are what I would expect from JavaFX (even if these is a performance hit).

Now try run the following (click image to toggle scale):

package imagescalingquality;
import javafx.stage.Stage;
import javafx.scene.Scene;
import javafx.scene.image.ImageView;
import javafx.scene.image.Image;
import javafx.scene.input.MouseEvent;
import javafx.util.Math;

var scale:Number = 1.0;
Stage {
    title: bind "JavaFX Image Scaling, Click Image Toggle Scale ({Math.ceil(scale * 100) as Integer}%)"
    scene: Scene {
        content: [
                ImageView {
                        image: Image {
                                url: "http://www.javafxtutorials.com/wp-content/uploads/2008/11/javafx_inkscape.png"
                        }
                        scaleX: bind scale
                        scaleY: bind scale
                        smooth: true
                        onMouseClicked: function( e: MouseEvent ):Void {
                                if (scale == 1.0){
                                    scale = 0.5
                                } else {
                                    scale = 1.0
                                }
                        }
                }
        ]
    }
}

The JavaFX image at 50% is much much worse than photoshop's effort. I really need a fix for this illegible text in our app is not really acceptable :'(

CHEERS :)

p.s. also raised this on the forum if these attachments are stripped or for more help reproducing the problem http://forums.sun.com/thread.jspa?threadID=5421113&tstart=0 
javafx_inkscape scale 1.0.png
javafx_inkscape scale 0.5.png

Andrew Hughes

unread,
Dec 22, 2009, 10:05:00 AM12/22/09
to jfxtr...@googlegroups.com
WooHoo, attachements get through. OK then... here's a screenshot of JavaFX's effort when the image is scaled @ 0.5 and smooth:true (i.e. the source code in the initial email).

Results are quite poor :'(
javafx_inkscape scale 0.5 (done with JavaFX).png

Goddard Jiri

unread,
Dec 22, 2009, 10:08:13 AM12/22/09
to jfxtr...@googlegroups.com
Hi,

the last image you sent is not scaled down by 50% but somewhat more. You can see it in both file size and picture size.

Regards, Jiri

--

You received this message because you are subscribed to the Google Groups "JFXtras Developers" group.
To post to this group, send email to jfxtr...@googlegroups.com.
To unsubscribe from this group, send email to jfxtras-dev...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/jfxtras-dev?hl=en.



--
web: http://dredwerkz.ic.cz
group: http://groups.google.com/group/dr3dwerkz
icq: 218 659 431

Andrew Hughes

unread,
Dec 22, 2009, 10:26:07 AM12/22/09
to jfxtr...@googlegroups.com
I just noticed that too when I saw them in the browser together.

My example's appear to have 'bugs' :/
1. JavaFX code does not scale the image to 0.5 despite what the code says <-- this is a unexpected.
2. The attachment 'javafx_inkscape scale 0.5.png' is not at 0.5 <-- my fault.... but the one attached to this email is @ 0.5.

No more attachments from me (I'm sure you all have enough now) :)

JavaFX really is doing a poor job (evidently so am I, please forgive me).  I don't really see what could be done to fix this. Even if I try and use JAI to scale the image, the scale is relative to the scene and JavaFX will probably resample/resize the image to achieve pixel to pixel 'on screen' 1.0 scale.
javafx_inkscape scale 0.5 (photoshop).png

Goddard Jiri

unread,
Dec 22, 2009, 10:50:17 AM12/22/09
to jfxtr...@googlegroups.com
I executed the code and, to be honest, I don't like the result also :)
If you use one of the Java 2D's built-in scaling hints, it will not give you proper results also.
Maybe somewhat better than JavaFX, but not as good as in Photoshop/Inkscape.
Chet Haase (former Sun Java Engineer, now in Adobe (codedependent.blogspot.com)) described this problem in his (and Romain Guy's) book Filthy Rich Clients. I might dig it up (I bought PDF version) or you can take a look at:
www.filthyrichclients.org into exapmples section and find the one with scaling algorithm.

Jiri

Jim Clarke

unread,
Dec 22, 2009, 12:35:27 PM12/22/09
to jfxtr...@googlegroups.com
Seems to do better when you manipulate fitWidth/fitHeight on ImageView rather than use scaleX/Y.

Also I checked the bounds of ImageView and I get:
width=1275.0, height=724.0 with Scale = 1.0
width=637.5, height=362.0 with Scale = 0.5.

jim
Jim Clarke
Principal Technologist
OEM Software Sales



Dean Iverson

unread,
Dec 22, 2009, 3:25:25 PM12/22/09
to jfxtr...@googlegroups.com
As Jim points out, using scaleX/Y is will only resize an ImageView.  If you want to resample the underlying image you should use the width/height vars in Image or use fitWidth/fitHeight on ImageView.

The following slightly modified version of your code will give much better results.

Dean

var scale: Number = 1.0;

Stage {
    title: bind "JavaFX Image Scaling, Click Image Toggle Scale ({Math.ceil(scale * 100) as Integer}%)"
    scene: Scene {
        content: [
            ImageView {
                var img: Image;
                image: img = Image {

                }
                fitWidth: bind img.width * scale;
                preserveRatio: true
                smooth: true
                onMouseClicked: function (e: MouseEvent): Void {

Andrew Hughes

unread,
Dec 22, 2009, 6:20:59 PM12/22/09
to jfxtr...@googlegroups.com
Excellent thanks! It definitely looks A LOT better that way...

Unfortunately, it's not quite the end of the story. The example shows an ImageView at the top of the Scene graph (i.e. has no parent node). So it fails to demonstrate relative parent/child scaling down the scene graph. An ImageView will inherit a parent's scale, for example 0.5 and thus will be applied/multiplied to the ImageView{} node. This means, you inevitably inherit bad image quality.

Me being the dumb person I am thought I would drag out the "native" scale of the ImageView with something like:

ImageView {
...
scaleX: bind 1 / parent.scaleX
scaleX: bind 1 / parent.scaleX

fitWidth: bind img.width * scale;
}

But that's plain stupid and falls apart once you have multiple scales along the scene graph, also when the scale changes dynamically it looks bad.

I've tried lot's of approached to resolve this, but nothing works. The only thing I could start to persue is to get JAI involved and start dynamically resizing buffered images to size based on the ImageView (native) bounds. Hopefully this idea sounds crazy and there is something better out there :'(


Help would be very much appreciated :)

Andrew Hughes

unread,
Dec 22, 2009, 8:30:42 PM12/22/09
to jfxtr...@googlegroups.com
I submitted a bug to JavaFX's Jira 'RT-6992', but I won't be able to see any future activity on the issue:

Issue Created Successfully

You have successfully created the issue (RT-6992), however you do not have the permission to view the created issue.

If you think this message is wrong, please consult your administrators about getting the necessary permissions.


Still trying to find a workaround....

Tom

unread,
Dec 23, 2009, 1:52:05 AM12/23/09
to jfxtr...@googlegroups.com
Happens to me all the time; then I contact the admin and he changes the permissions for me for that one bug.

Pedro Duque Vieira

unread,
Dec 23, 2009, 6:40:56 AM12/23/09
to jfxtr...@googlegroups.com

Yes, that’s something that is really annoying.

You’ll never be able to track you’re bug report, if it got through to the dev team, if they’re fixing it, if they acknowledge it….

Pedro Duque Vieira

unread,
Dec 23, 2009, 6:42:08 AM12/23/09
to jfxtr...@googlegroups.com

Humm.. I have contacted the admin and nothing happened.

 

Guess I’ll try that again the next time.

 

From: jfxtr...@googlegroups.com [mailto:jfxtr...@googlegroups.com] On Behalf Of Tom
Sent: quarta-feira, 23 de Dezembro de 2009 06:52
To: jfxtr...@googlegroups.com
Subject: Re: Image scaling is very poor

 

Happens to me all the time; then I contact the admin and he changes the permissions for me for that one bug.

--

Jim Clarke

unread,
Dec 23, 2009, 10:31:26 AM12/23/09
to jfxtr...@googlegroups.com
Did you want the priority to be minor?

jim

Andrew Hughes

unread,
Dec 30, 2009, 5:55:08 PM12/30/09
to jfxtr...@googlegroups.com
Not sure who you are asking Jim :)

I think this is major. There are no workarounds and images can't be avoided. Also, it's unlikely that commercial/popular JavaFX UI's will be run at their native resolution. Especially when considering the nature of:
  • Mobile Devices - such limited real estate to work with, you really need to use every pixel you can.
  • Browser or widget style screen space - get what screen space you're given and deal with it.
  • Desktop apps - everything from netbooks to 1080HD, radically different resolutions.
Sounds like JavaFX's market space to me....  :)


Have a good NYE everyone!

Jim Clarke

unread,
Dec 30, 2009, 8:00:48 PM12/30/09
to jfxtr...@googlegroups.com
Andrew, I raised the severity to Major. Hopefully, this will help it along.

jim

Andrew Hughes

unread,
Jan 2, 2010, 5:26:26 PM1/2/10
to jfxtr...@googlegroups.com
Thanks Heaps Jim!

Is there any chance I can have permissions to see the issue please?

--AH

Jim Clarke

unread,
Jan 2, 2010, 6:47:32 PM1/2/10
to jfxtr...@googlegroups.com
Sorry, but I don't have permission to do that.

Jim Clarke
Principal Engineer, OEM Software Sales
Sun Microsystems, Inc.

----------Original Message----------

From: Andrew Hughes <ahhu...@gmail.com>
Sent: Sat, January 02, 2010 5:26 PM
To: jfxtr...@googlegroups.com
Subject: Re: Image scaling is very poor

Thanks Heaps Jim!

Is there any chance I can have permissions to see the issue please?

--AH


On Thu, Dec 31, 2009 at 11:30 AM, Jim Clarke <Jim.C...@sun.com> wrote:

> Andrew, I raised the severity to Major. Hopefully, this will help it along.
>
> jim
>
> On Dec 30, 2009, at 5:55 PM, Andrew Hughes wrote:
>
> Not sure who you are asking Jim :)
>
> I think this is major. There are no workarounds and images can't be
> avoided. Also, it's unlikely that commercial/popular JavaFX UI's will be run
> at their native resolution. Especially when considering the nature of:
>

> - Mobile Devices - such limited real estate to work with, you really


> need to use every pixel you can.

> - Browser or widget style screen space - get what screen space you're


> given and deal with it.

> - Desktop apps - everything from netbooks to 1080HD, radically


> different resolutions.
>
> Sounds like JavaFX's market space to me.... :)
>
>
> Have a good NYE everyone!
>
>
> On Thu, Dec 24, 2009 at 2:01 AM, Jim Clarke <Jim.C...@sun.com> wrote:
>
>> Did you want the priority to be minor?
>>
>> jim
>>
>> On Dec 22, 2009, at 8:30 PM, Andrew Hughes wrote:
>>
>> I submitted a bug to JavaFX's Jira 'RT-6992', but I won't be able to see
>> any future activity on the issue:
>>
>> Issue Created Successfully You have successfully created the issue
>> (RT-6992), however you do not have the permission to view the created issue.
>>

>> If you think this message is wrong, please consult your administrators<http://javafx-jira.kenai.com/secure/Administrators.jspa> about

>>>>>> *No more attachments from me (I'm sure you all have enough now) :)*

>>>>>>>> jfxtras-dev...@googlegroups.com<jfxtras-dev%2Bunsu...@googlegroups.com>


>>>>>>>> .
>>>>>>>> For more options, visit this group at
>>>>>>>> http://groups.google.com/group/jfxtras-dev?hl=en.
>>>>>>>>
>>>>>>>
>>>>>>>
>>>>>>>
>>>>>>> --
>>>>>>> web: http://dredwerkz.ic.cz
>>>>>>> group: http://groups.google.com/group/dr3dwerkz
>>>>>>> icq: 218 659 431
>>>>>>>
>>>>>>> --
>>>>>>> You received this message because you are subscribed to the Google
>>>>>>> Groups "JFXtras Developers" group.
>>>>>>> To post to this group, send email to jfxtr...@googlegroups.com.
>>>>>>> To unsubscribe from this group, send email to

>>>>>>> jfxtras-dev...@googlegroups.com<jfxtras-dev%2Bunsu...@googlegroups.com>


>>>>>>> .
>>>>>>> For more options, visit this group at
>>>>>>> http://groups.google.com/group/jfxtras-dev?hl=en.
>>>>>>>
>>>>>>
>>>>>>
>>>>>> --
>>>>>> You received this message because you are subscribed to the Google
>>>>>> Groups "JFXtras Developers" group.
>>>>>> To post to this group, send email to jfxtr...@googlegroups.com.
>>>>>> To unsubscribe from this group, send email to

>>>>>> jfxtras-dev...@googlegroups.com<jfxtras-dev%2Bunsu...@googlegroups.com>


>>>>>> .
>>>>>> For more options, visit this group at
>>>>>> http://groups.google.com/group/jfxtras-dev?hl=en.
>>>>>>
>>>>>
>>>>>
>>>>>
>>>>> --
>>>>> web: http://dredwerkz.ic.cz
>>>>> group: http://groups.google.com/group/dr3dwerkz
>>>>> icq: 218 659 431
>>>>>
>>>>> --
>>>>> You received this message because you are subscribed to the Google
>>>>> Groups "JFXtras Developers" group.
>>>>> To post to this group, send email to jfxtr...@googlegroups.com.
>>>>> To unsubscribe from this group, send email to
>>>>> jfxtras-dev...@googlegroups.com.
>>>>> For more options, visit this group at
>>>>> http://groups.google.com/group/jfxtras-dev?hl=en.
>>>>>
>>>>>
>>>>> Jim Clarke
>>>>> Principal Technologist
>>>>> OEM Software Sales
>>>>> jim.c...@sun.com
>>>>>
>>>>>
>>>>>
>>>>>
>>>>> --
>>>>> You received this message because you are subscribed to the Google
>>>>> Groups "JFXtras Developers" group.
>>>>> To post to this group, send email to jfxtr...@googlegroups.com.
>>>>> To unsubscribe from this group, send email to

>>>>> jfxtras-dev...@googlegroups.com<jfxtras-dev%2Bunsu...@googlegroups.com>


>>>>> .
>>>>> For more options, visit this group at
>>>>> http://groups.google.com/group/jfxtras-dev?hl=en.
>>>>>
>>>>
>>>>
>>>> --
>>>> You received this message because you are subscribed to the Google
>>>> Groups "JFXtras Developers" group.
>>>> To post to this group, send email to jfxtr...@googlegroups.com.
>>>> To unsubscribe from this group, send email to

>>>> jfxtras-dev...@googlegroups.com<jfxtras-dev%2Bunsu...@googlegroups.com>


>>>> .
>>>> For more options, visit this group at
>>>> http://groups.google.com/group/jfxtras-dev?hl=en.
>>>>
>>>
>>>
>>
>> --
>> You received this message because you are subscribed to the Google Groups
>> "JFXtras Developers" group.
>> To post to this group, send email to jfxtr...@googlegroups.com.
>> To unsubscribe from this group, send email to
>> jfxtras-dev...@googlegroups.com.
>> For more options, visit this group at
>> http://groups.google.com/group/jfxtras-dev?hl=en.
>>
>>
>> Jim Clarke
>> Principal Technologist
>> OEM Software Sales
>> jim.c...@sun.com
>>
>>
>>
>>
>> --
>> You received this message because you are subscribed to the Google Groups
>> "JFXtras Developers" group.
>> To post to this group, send email to jfxtr...@googlegroups.com.
>> To unsubscribe from this group, send email to

>> jfxtras-dev...@googlegroups.com<jfxtras-dev%2Bunsu...@googlegroups.com>


>> .
>> For more options, visit this group at
>> http://groups.google.com/group/jfxtras-dev?hl=en.
>>
>
>
> --
> You received this message because you are subscribed to the Google Groups
> "JFXtras Developers" group.
> To post to this group, send email to jfxtr...@googlegroups.com.
> To unsubscribe from this group, send email to
> jfxtras-dev...@googlegroups.com.
> For more options, visit this group at
> http://groups.google.com/group/jfxtras-dev?hl=en.
>
>
> Jim Clarke
> Principal Technologist
> OEM Software Sales
> jim.c...@sun.com
>
>
>
> --
> You received this message because you are subscribed to the Google Groups
> "JFXtras Developers" group.
> To post to this group, send email to jfxtr...@googlegroups.com.
> To unsubscribe from this group, send email to

> jfxtras-dev...@googlegroups.com<jfxtras-dev%2Bunsu...@googlegroups.com>

Jim Clarke

unread,
Feb 3, 2010, 11:35:07 AM2/3/10
to jfxtr...@googlegroups.com
I have an explanation to this issue.

====
This is a natural consequence of odd-sized images being scaled from the center of the image.  Gimp is scaling the image from the left edge and so sampling every other pixel tends to sample the edges between pairs of pixels and so blending captures the data from all of the pixels.  Unfortunately the FX operation scales the image from its center and since the image is an odd number of pixels wide the center in the X direction is the center of the middle pixel.  The samplings then progresses outward from there hitting the center of every other pixel. Note that with LINEAR sampling, if you sample the center of a pixel then the result is that pixel with no blending of the pixels on either side.  So, if you run through the image sampling every other pixel at its center then you get only the data from those pixels and the pixels that are skipped over are completely omitted from the image.

====

I have asked the follow-up question if you use a Scale transform with pivotX/Y = 0,0 would that
solve the problem. 

I haven't had time to check it out myself though.


jim

--

You received this message because you are subscribed to the Google Groups "JFXtras Developers" group.
To post to this group, send email to jfxtr...@googlegroups.com.
To unsubscribe from this group, send email to jfxtras-dev...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/jfxtras-dev?hl=en.
<javafx_inkscape scale 1.0.png><javafx_inkscape scale 0.5.png>

Pedro Duque Vieira

unread,
Feb 3, 2010, 11:46:32 AM2/3/10
to jfxtr...@googlegroups.com

I have a zoom feature on my app. Zooming works by applying a scale factor to the origin of the scene with a pivot point of X/Y = 0,0.

I’m satisfied with the results.  I can see that some rendering optimization is being performed by JavaFX, I haven’t however made any comparisons with image editing software like photoshop.

 

Cheers,
Pedro

 

From: jfxtr...@googlegroups.com [mailto:jfxtr...@googlegroups.com] On Behalf Of Jim Clarke
Sent: quarta-feira, 3 de Fevereiro de 2010 16:35
To: jfxtr...@googlegroups.com
Subject: Re: Image scaling is very poor

 

I have an explanation to this issue.

Reply all
Reply to author
Forward
0 new messages