When you think of digital images, you probably think of sampled image formats such as the JPEG image format used in digital photography, or GIF images commonly used on web pages. All programs that can use these images must first convert them from that external format into an internal format.
Java supports loading these external image formats into its BufferedImage format using its Image I/O API which is in the javax.imageio package. Image I/O has built-in support for GIF, PNG, JPEG, BMP, and WBMP.
Below is the code to Load Image in Applet from a URL using BufferedImage class to minimize flickering.
import java.applet.*; import java.awt.*; import java.awt.image.*; import java.net.*; import javax.imageio.*; /** * * @author Originative */ public class LoadImageInApplet extends Applet{ BufferedImage image; @Override public void init() { // Load image try{ URL url=new URL("https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhPXuqtqoMJe7qiBzdoL_Xk5q72Z47Hg6TuSIlaJS-joM-O0cLPkrs8JKvN9x-8BQFve5T923ZAJ8DE0-qwK1Zc7jgdMDqcQQETxpfhsGQDSI5Pwe8mZ-AZFgHBEXvfAtEtNniuWoEO_jA/s200/java.png"); image = ImageIO.read(url); } catch(Exception ex){ } } @Override public void paint(Graphics g) { // Draw image g.drawImage(image, 0, 0, this); } }when you run this you will see something similar to this.
1 comments:
java programming applets
Walking Text
Post a Comment