Skip to content

Commit 5e90cc5

Browse files
committed
Added helper method to scale images in Theme class
1 parent 494d4bf commit 5e90cc5

File tree

1 file changed

+19
-1
lines changed

1 file changed

+19
-1
lines changed

app/src/processing/app/Theme.java

+19-1
Original file line numberDiff line numberDiff line change
@@ -575,6 +575,12 @@ 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);
@@ -590,10 +596,22 @@ static public Image getLibImage(String filename, Component who, int width,
590596
} catch (InterruptedException e) {
591597
}
592598
}
593-
594599
return image;
595600
}
596601

602+
public static Image scale(Image image, Component who) {
603+
MediaTracker tracker = new MediaTracker(who);
604+
try {
605+
tracker.addImage(image, 0);
606+
tracker.waitForAll();
607+
} catch (InterruptedException e) {
608+
}
609+
610+
int w = image.getWidth(null);
611+
int h = image.getHeight(null);
612+
return rescaleImage(image, who, scale(w), scale(h));
613+
}
614+
597615
/**
598616
* Get an image associated with the current color theme.
599617
*/

0 commit comments

Comments
 (0)