@@ -575,23 +575,42 @@ static public Image getLibImage(String filename, Component who, int width,
575575 image = tk .getImage (imageFile .getUrl ());
576576 }
577577
578+ image = rescaleImage (image , who , width , height );
579+
580+ return image ;
581+ }
582+
583+ public static Image rescaleImage (Image image , Component who , int width , int height ) {
578584 MediaTracker tracker = new MediaTracker (who );
579585 try {
580586 tracker .addImage (image , 0 );
581587 tracker .waitForAll ();
582588 } catch (InterruptedException e ) {
583589 }
590+ if (image .getWidth (null ) == width && image .getHeight (null ) == height ) {
591+ return image ;
592+ }
584593
585- if (image .getWidth (null ) != width || image .getHeight (null ) != height ) {
586- image = image .getScaledInstance (width , height , Image .SCALE_SMOOTH );
587- try {
588- tracker .addImage (image , 1 );
589- tracker .waitForAll ();
590- } catch (InterruptedException e ) {
591- }
594+ Image rescaled = image .getScaledInstance (width , height , Image .SCALE_SMOOTH );
595+ try {
596+ tracker .addImage (rescaled , 1 );
597+ tracker .waitForAll ();
598+ } catch (InterruptedException e ) {
592599 }
600+ return rescaled ;
601+ }
593602
594- return image ;
603+ public static Image scale (Image image , Component who ) {
604+ MediaTracker tracker = new MediaTracker (who );
605+ try {
606+ tracker .addImage (image , 0 );
607+ tracker .waitForAll ();
608+ } catch (InterruptedException e ) {
609+ }
610+
611+ int w = image .getWidth (null );
612+ int h = image .getHeight (null );
613+ return rescaleImage (image , who , scale (w ), scale (h ));
595614 }
596615
597616 /**
0 commit comments