@@ -575,23 +575,42 @@ static public Image getLibImage(String filename, Component who, int width,
575
575
image = tk .getImage (imageFile .getUrl ());
576
576
}
577
577
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 ) {
578
584
MediaTracker tracker = new MediaTracker (who );
579
585
try {
580
586
tracker .addImage (image , 0 );
581
587
tracker .waitForAll ();
582
588
} catch (InterruptedException e ) {
583
589
}
590
+ if (image .getWidth (null ) == width && image .getHeight (null ) == height ) {
591
+ return image ;
592
+ }
584
593
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 ) {
592
599
}
600
+ return rescaled ;
601
+ }
593
602
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 ));
595
614
}
596
615
597
616
/**
0 commit comments