Here you can find the source of getImageImmediate(final Image image)
Parameter | Description |
---|---|
image | the image you want load immediately |
public static Image getImageImmediate(final Image image)
//package com.java2s; /*//from w ww . ja va2s .c o m * Copyright 2016 dorkbox, llc * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ import java.awt.Image; import javax.swing.ImageIcon; public class Main { /** * Because of the way image loading works in Java, if one wants to IMMEDIATELY get a fully loaded image, one must resort to "hacks" * by loading the image twice. * * @param image the image you want load immediately * * @return a fully loaded image */ public static Image getImageImmediate(final Image image) { // have to do this twice, so that it will finish loading the image (weird callback stuff is required if we don't do this) image.flush(); final Image loadedImage = new ImageIcon(image).getImage(); loadedImage.flush(); return loadedImage; } }