MCPcopy Create free account
hub / github.com/codenameone/CodenameOne / fill

Method fill

CodenameOne/src/com/codename1/ui/Image.java:1880–1895  ·  view source on GitHub ↗
(int width, int height)

Source from the content-addressed store, hash-verified

1878 ///
1879 /// a new image (or the same image if dimensions happen to match) filling the width/height
1880 public Image fill(int width, int height) {
1881 if (getWidth() == width && getHeight() == height) {
1882 return this;
1883 }
1884 Image nimage = scaledLargerRatio(width, height);
1885 if (nimage.getWidth() > width) {
1886 int diff = nimage.getWidth() - width;
1887 nimage = nimage.subImage(diff / 2, 0, width, height, true);
1888 } else {
1889 if (nimage.getHeight() > height) {
1890 int diff = nimage.getHeight() - height;
1891 nimage = nimage.subImage(0, diff / 2, width, height, true);
1892 }
1893 }
1894 return nimage;
1895 }
1896
1897 /// Returns the platform specific image implementation, **warning** the
1898 /// implementation class can change between revisions of Codename One and platforms.

Callers 1

testFillMethod · 0.95

Calls 4

getWidthMethod · 0.95
getHeightMethod · 0.95
scaledLargerRatioMethod · 0.95
subImageMethod · 0.95

Tested by 1

testFillMethod · 0.76