Java Image getImageImmediate(final Image image)

Here you can find the source of getImageImmediate(final Image image)

Description

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.

License

Apache License

Parameter

Parameter Description
image the image you want load immediately

Return

a fully loaded image

Declaration

public static Image getImageImmediate(final Image image) 

Method Source Code

//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;
    }
}

Related

  1. getColoredImage(Color color, int width, int height)
  2. getDisabledImage(Image image)
  3. getEingabeImage(int x, int y)
  4. getHeight(Image imagen)
  5. getImageByFilename(String filename)
  6. GetImagenConTamanioDado(File file, int ancho, int alto)
  7. getImageWithBorder(Image imagen)
  8. getInputStreamFromImage(Image imagen, String format)
  9. getLogoImage()