private BufferedImage convertToBufferedImage(Image image) throws IOException {
if (image instanceof BufferedImage) {
return (BufferedImage)image;
} else {
MediaTracker tracker = new MediaTracker(new Component(){}); // not sure if this is the right thing to do.
tracker.addImage(image, 0);
try {
tracker.waitForAll();
} catch (InterruptedException e) {
throw new IOException(e.getMessage());
}
BufferedImage bufImage = new BufferedImage(
image.getWidth(null),
image.getHeight(null),
BufferedImage.TYPE_INT_ARGB);
Graphics g = bufImage.createGraphics();
g.drawImage(image, 0, 0, null);
return bufImage;
}
}
java类java.awt.MediaTracker的实例源码
RuntimeBuiltinLeafInfoImpl.java 文件源码
项目:OpenJSharp
阅读 28
收藏 0
点赞 0
评论 0
MultiResolutionImageTest.java 文件源码
项目:jdk8u-jdk
阅读 20
收藏 0
点赞 0
评论 0
static void testToolkitMultiResolutionImageLoad(Image image) throws Exception {
MediaTracker tracker = new MediaTracker(new JPanel());
tracker.addImage(image, 0);
tracker.waitForID(0);
if (tracker.isErrorAny()) {
throw new RuntimeException("Error during image loading");
}
tracker.removeImage(image, 0);
testImageLoaded(image);
int w = image.getWidth(null);
int h = image.getHeight(null);
Image resolutionVariant = ((MultiResolutionImage) image)
.getResolutionVariant(2 * w, 2 * h);
if (image == resolutionVariant) {
throw new RuntimeException("Resolution variant is not loaded");
}
testImageLoaded(resolutionVariant);
}
MultiResolutionImageTest.java 文件源码
项目:openjdk-jdk10
阅读 22
收藏 0
点赞 0
评论 0
static void testToolkitMultiResolutionImageLoad(Image image)
throws Exception {
MediaTracker tracker = new MediaTracker(new JPanel());
tracker.addImage(image, 0);
tracker.waitForID(0);
if (tracker.isErrorAny()) {
throw new RuntimeException("Error during image loading");
}
tracker.removeImage(image, 0);
testImageLoaded(image);
int w = image.getWidth(null);
int h = image.getHeight(null);
Image resolutionVariant = ((MultiResolutionImage) image)
.getResolutionVariant(2 * w, 2 * h);
if (image == resolutionVariant) {
throw new RuntimeException("Resolution variant is not loaded");
}
testImageLoaded(resolutionVariant);
}
RuntimeBuiltinLeafInfoImpl.java 文件源码
项目:openjdk-jdk10
阅读 24
收藏 0
点赞 0
评论 0
private BufferedImage convertToBufferedImage(Image image) throws IOException {
if (image instanceof BufferedImage) {
return (BufferedImage)image;
} else {
MediaTracker tracker = new MediaTracker(new Component(){}); // not sure if this is the right thing to do.
tracker.addImage(image, 0);
try {
tracker.waitForAll();
} catch (InterruptedException e) {
throw new IOException(e.getMessage());
}
BufferedImage bufImage = new BufferedImage(
image.getWidth(null),
image.getHeight(null),
BufferedImage.TYPE_INT_ARGB);
Graphics g = bufImage.createGraphics();
g.drawImage(image, 0, 0, null);
return bufImage;
}
}
MultiResolutionImageTest.java 文件源码
项目:openjdk9
阅读 24
收藏 0
点赞 0
评论 0
static void testToolkitMultiResolutionImageLoad(Image image)
throws Exception {
MediaTracker tracker = new MediaTracker(new JPanel());
tracker.addImage(image, 0);
tracker.waitForID(0);
if (tracker.isErrorAny()) {
throw new RuntimeException("Error during image loading");
}
tracker.removeImage(image, 0);
testImageLoaded(image);
int w = image.getWidth(null);
int h = image.getHeight(null);
Image resolutionVariant = ((MultiResolutionImage) image)
.getResolutionVariant(2 * w, 2 * h);
if (image == resolutionVariant) {
throw new RuntimeException("Resolution variant is not loaded");
}
testImageLoaded(resolutionVariant);
}
RuntimeBuiltinLeafInfoImpl.java 文件源码
项目:openjdk9
阅读 29
收藏 0
点赞 0
评论 0
private BufferedImage convertToBufferedImage(Image image) throws IOException {
if (image instanceof BufferedImage) {
return (BufferedImage)image;
} else {
MediaTracker tracker = new MediaTracker(new Component(){}); // not sure if this is the right thing to do.
tracker.addImage(image, 0);
try {
tracker.waitForAll();
} catch (InterruptedException e) {
throw new IOException(e.getMessage());
}
BufferedImage bufImage = new BufferedImage(
image.getWidth(null),
image.getHeight(null),
BufferedImage.TYPE_INT_ARGB);
Graphics g = bufImage.createGraphics();
g.drawImage(image, 0, 0, null);
return bufImage;
}
}
xtGraphics.java 文件源码
项目:OpenNFMM
阅读 18
收藏 0
点赞 0
评论 0
static private void loadimages() {
final Toolkit toolkit = Toolkit.getDefaultToolkit();
final MediaTracker mediatracker = new MediaTracker(app);
dnload += 8;
try {
for (int i = 0; i < idts.length; i++) {
idts[i].cons.accept(Files.readAllBytes(new File(Madness.fpath + "data/images/" + idts[i].fileName).toPath()), mediatracker, toolkit);
}
dnload += 2;
} catch (final Exception exception) {
System.err.println("Error Loading Images: " + exception);
}
System.gc();
}
ImageLoader.java 文件源码
项目:PhET
阅读 26
收藏 0
点赞 0
评论 0
public Image fetchImage( URL imageLocation ) throws IOException {
Image image = null;
try {
if ( imageLocation == null ) {
throw new IOException( "Image resource not found: Null imagelocation URL" );
}
else {
Toolkit toolkit = Toolkit.getDefaultToolkit();
image = toolkit.createImage( imageLocation );
MediaTracker tracker = new MediaTracker( this );
tracker.addImage( image, 0 );
tracker.waitForAll();
}
}
catch ( InterruptedException e ) {
}
return image;
}
AppletLoader.java 文件源码
项目:PhET
阅读 18
收藏 0
点赞 0
评论 0
/**
* Get Image from path provided
*
* @param url location of the image
* @return the Image file
*/
public Image getImage(URL url) {
try {
MediaTracker tracker = new MediaTracker(this);
Image image = super.getImage(url);
// wait for image to load
tracker.addImage(image, 0);
tracker.waitForAll();
// if no errors return image
if (!tracker.isErrorAny()) {
return image;
}
} catch (Exception e) {
/* */
}
return null;
}
Viewer.java 文件源码
项目:PhET
阅读 25
收藏 0
点赞 0
评论 0
public Image getFileAsImage(String pathName, String[] retFileNameOrError) {
if (!haveDisplay) {
retFileNameOrError[0] = "no display";
return null;
}
Image image = fileManager.getFileAsImage(pathName, retFileNameOrError);
if (image == null)
return null;
MediaTracker tracker = new MediaTracker(display);
tracker.addImage(image, 0);
try {
tracker.waitForID(0);
} catch (InterruptedException e) {
// Got to do something?
}
return image;
}
JasperApp.java 文件源码
项目:jasperreports
阅读 24
收藏 0
点赞 0
评论 0
/**
*
*/
public void run() throws JRException
{
long start = System.currentTimeMillis();
//Preparing parameters
Image image = Toolkit.getDefaultToolkit().createImage("dukesign.jpg");
MediaTracker traker = new MediaTracker(new Panel());
traker.addImage(image, 0);
try
{
traker.waitForID(0);
}
catch (Exception e)
{
e.printStackTrace();
}
Map<String, Object> parameters = new HashMap<String, Object>();
parameters.put("ReportTitle", "The First Jasper Report Ever");
parameters.put("MaxOrderID", new Integer(10500));
parameters.put("SummaryImage", image);
JasperRunManager.runReportToPdfFile("build/reports/FirstJasper.jasper", parameters, getDemoHsqldbConnection());
System.err.println("PDF running time : " + (System.currentTimeMillis() - start));
}
Splash.java 文件源码
项目:JSmooth
阅读 27
收藏 0
点赞 0
评论 0
public Splash(Frame parent, String imagefilename, boolean dialog)
{
if (dialog)
{
m_window = new MyDialog(parent);
}
else
{
m_window = new MyWindow(parent);
}
javax.swing.ImageIcon icon = new javax.swing.ImageIcon(getClass().getResource(imagefilename));
m_splashImage = icon.getImage();
MediaTracker loader = new MediaTracker(m_window);
loader.addImage(m_splashImage, 0);
try {
loader.waitForAll();
} catch (Exception e) {}
}
MultiResolutionImageTest.java 文件源码
项目:jdk8u_jdk
阅读 40
收藏 0
点赞 0
评论 0
static void testToolkitMultiResolutionImageLoad(Image image)
throws Exception {
MediaTracker tracker = new MediaTracker(new JPanel());
tracker.addImage(image, 0);
tracker.waitForID(0);
if (tracker.isErrorAny()) {
throw new RuntimeException("Error during image loading");
}
tracker.removeImage(image, 0);
testImageLoaded(image);
int w = image.getWidth(null);
int h = image.getHeight(null);
Image resolutionVariant = ((MultiResolutionImage) image)
.getResolutionVariant(2 * w, 2 * h);
if (image == resolutionVariant) {
throw new RuntimeException("Resolution variant is not loaded");
}
testImageLoaded(resolutionVariant);
}
MultiResolutionImageTest.java 文件源码
项目:lookaside_java-1.8.0-openjdk
阅读 28
收藏 0
点赞 0
评论 0
static void testToolkitMultiResolutionImageLoad(Image image) throws Exception {
MediaTracker tracker = new MediaTracker(new JPanel());
tracker.addImage(image, 0);
tracker.waitForID(0);
if (tracker.isErrorAny()) {
throw new RuntimeException("Error during image loading");
}
tracker.removeImage(image, 0);
testImageLoaded(image);
int w = image.getWidth(null);
int h = image.getHeight(null);
Image resolutionVariant = ((MultiResolutionImage) image)
.getResolutionVariant(2 * w, 2 * h);
if (image == resolutionVariant) {
throw new RuntimeException("Resolution variant is not loaded");
}
testImageLoaded(resolutionVariant);
}
RuntimeBuiltinLeafInfoImpl.java 文件源码
项目:lookaside_java-1.8.0-openjdk
阅读 37
收藏 0
点赞 0
评论 0
private BufferedImage convertToBufferedImage(Image image) throws IOException {
if (image instanceof BufferedImage) {
return (BufferedImage)image;
} else {
MediaTracker tracker = new MediaTracker(new Component(){}); // not sure if this is the right thing to do.
tracker.addImage(image, 0);
try {
tracker.waitForAll();
} catch (InterruptedException e) {
throw new IOException(e.getMessage());
}
BufferedImage bufImage = new BufferedImage(
image.getWidth(null),
image.getHeight(null),
BufferedImage.TYPE_INT_ARGB);
Graphics g = bufImage.createGraphics();
g.drawImage(image, 0, 0, null);
return bufImage;
}
}
AudioDevicesPage.java 文件源码
项目:LS-jsampler
阅读 17
收藏 0
点赞 0
评论 0
DuplicateAudioDevice() {
super("");
putValue(SHORT_DESCRIPTION, i18n.getMenuLabel("ttDuplicateAudioDevice"));
try {
URL url = ClassLoader.getSystemClassLoader().getResource (
"org/jsampler/view/classic/res/icons/Copy16.gif"
);
ImageIcon icon = new ImageIcon(url);
if(icon.getImageLoadStatus() == MediaTracker.COMPLETE)
putValue(Action.SMALL_ICON, icon);
} catch(Exception x) {
CC.getLogger().log(Level.INFO, HF.getErrorMessage(x), x);
}
setEnabled(false);
}
AudioDevicesPage.java 文件源码
项目:LS-jsampler
阅读 18
收藏 0
点赞 0
评论 0
RemoveAudioDevice() {
super("");
putValue(SHORT_DESCRIPTION, i18n.getMenuLabel("ttRemoveAudioDevice"));
try {
URL url = ClassLoader.getSystemClassLoader().getResource (
"org/jsampler/view/classic/res/icons/Delete16.gif"
);
ImageIcon icon = new ImageIcon(url);
if(icon.getImageLoadStatus() == MediaTracker.COMPLETE)
putValue(Action.SMALL_ICON, icon);
} catch(Exception x) {
CC.getLogger().log(Level.INFO, HF.getErrorMessage(x), x);
}
setEnabled(false);
}
AudioDevicesPage.java 文件源码
项目:LS-jsampler
阅读 93
收藏 0
点赞 0
评论 0
AudioDeviceProps() {
super("");
putValue(SHORT_DESCRIPTION, i18n.getMenuLabel("ttAudioDeviceProps"));
try {
URL url = ClassLoader.getSystemClassLoader().getResource (
"org/jsampler/view/classic/res/icons/Properties16.gif"
);
ImageIcon icon = new ImageIcon(url);
if(icon.getImageLoadStatus() == MediaTracker.COMPLETE)
putValue(Action.SMALL_ICON, icon);
} catch(Exception x) {
CC.getLogger().log(Level.INFO, HF.getErrorMessage(x), x);
}
setEnabled(false);
}
ImageViewer.java 文件源码
项目:javify
阅读 24
收藏 0
点赞 0
评论 0
public void setCommandContext(String verb, DataHandler dh)
throws IOException
{
// Read image into a byte array
InputStream in = dh.getInputStream();
ByteArrayOutputStream bytes = new ByteArrayOutputStream();
byte[] buf = new byte[4096];
for (int len = in.read(buf); len != -1; len = in.read(buf))
bytes.write(buf, 0, len);
in.close();
// Create and prepare the image
Toolkit toolkit = getToolkit();
Image img = toolkit.createImage(bytes.toByteArray());
try
{
MediaTracker tracker = new MediaTracker(this);
tracker.addImage(img, 0);
tracker.waitForID(0);
}
catch (InterruptedException e)
{
}
toolkit.prepareImage(img, -1, -1, this);
}
Bounce.java 文件源码
项目:code-similarity
阅读 18
收藏 0
点赞 0
评论 0
public void init() {
Button b = new Button("Start");
b.addActionListener(this);
setLayout(new BorderLayout());
add(b, BorderLayout.NORTH);
add(p = new Panel(), BorderLayout.CENTER);
p.setLayout(null);
String imgName = getParameter("imagefile");
if (imgName == null) imgName = "duke.gif";
img = getImage(getCodeBase(), imgName);
MediaTracker mt = new MediaTracker(this);
mt.addImage(img, 0);
try {
mt.waitForID(0);
} catch(InterruptedException e) {
throw new IllegalArgumentException(
"InterruptedException while loading image " + imgName);
}
if (mt.isErrorID(0)) {
throw new IllegalArgumentException(
"Couldn't load image " + imgName);
}
v = new Vector<Sprite>(); // multithreaded, use Vector
}
CannedMarsMap.java 文件源码
项目:mars-sim
阅读 15
收藏 0
点赞 0
评论 0
/**
* Creates a 2D map at a given center point.
* @param newCenter the new center location
*/
public void drawMap(Coordinates newCenter) {
if ((newCenter != null) && (!newCenter.equals(currentCenter))) {
mapImage = createMapImage(newCenter);
MediaTracker mt = new MediaTracker(displayArea);
mt.addImage(mapImage, 0);
try {
mt.waitForID(0);
}
catch (InterruptedException e) {
logger.log(Level.SEVERE,Msg.getString("CannedMarsMap.log.mediaTrackerInterrupted") + e); //$NON-NLS-1$
}
mapImageDone = true;
currentCenter = new Coordinates(newCenter);
}
}
ReliefImageBreaker.java 文件源码
项目:triplea
阅读 16
收藏 0
点赞 0
评论 0
/**
* Asks the user to select an image and then it loads it up into an Image
* object and returns it to the calling class.
*
* @return java.awt.Image img the loaded image
*/
private static Image loadImage() {
System.out.println("Select the map");
final String mapName = new FileOpen("Select The Map", mapFolderLocation, ".gif", ".png").getPathString();
if (mapName != null) {
final Image img = Toolkit.getDefaultToolkit().createImage(mapName);
final MediaTracker tracker = new MediaTracker(new Panel());
tracker.addImage(img, 1);
try {
tracker.waitForAll();
return img;
} catch (final InterruptedException e) {
Thread.currentThread().interrupt();
}
}
return null;
}
TileImageBreaker.java 文件源码
项目:triplea
阅读 16
收藏 0
点赞 0
评论 0
/**
* java.awt.Image loadImage()
* Asks the user to select an image and then it loads it up into an Image
* object and returns it to the calling class.
*
* @return java.awt.Image img the loaded image
*/
private static Image loadImage() {
System.out.println("Select the map");
final String mapName = new FileOpen("Select The Map", mapFolderLocation, ".gif", ".png").getPathString();
if (mapName != null) {
final Image img = Toolkit.getDefaultToolkit().createImage(mapName);
final MediaTracker tracker = new MediaTracker(new Panel());
tracker.addImage(img, 1);
try {
tracker.waitForAll();
return img;
} catch (final InterruptedException e) {
Thread.currentThread().interrupt();
}
}
return null;
}
ImageViewer.java 文件源码
项目:jvm-stm
阅读 26
收藏 0
点赞 0
评论 0
public void setCommandContext(String verb, DataHandler dh)
throws IOException
{
// Read image into a byte array
InputStream in = dh.getInputStream();
ByteArrayOutputStream bytes = new ByteArrayOutputStream();
byte[] buf = new byte[4096];
for (int len = in.read(buf); len != -1; len = in.read(buf))
bytes.write(buf, 0, len);
in.close();
// Create and prepare the image
Toolkit toolkit = getToolkit();
Image img = toolkit.createImage(bytes.toByteArray());
try
{
MediaTracker tracker = new MediaTracker(this);
tracker.addImage(img, 0);
tracker.waitForID(0);
}
catch (InterruptedException e)
{
}
toolkit.prepareImage(img, -1, -1, this);
}
GifUtil.java 文件源码
项目:chatty
阅读 18
收藏 0
点赞 0
评论 0
/**
* Loads a GIF from the given URL, fixing FPS, or just creates an ImageIcon
* directly if it's not a valid GIF.
*
* @param url The URL (local or internet) to get the image data from
* @return The created ImageIcon, or null if an error occured creating the
* image
* @throws Exception When an error occured loading the image
*/
public static ImageIcon getGifFromUrl(URL url) throws Exception {
try (InputStream input = url.openStream()) {
// Use readAllBytes() because GifDecoder doesn't handle streams well
byte[] imageData = readAllBytes(input);
ImageIcon image = null;
try {
//System.out.println(hash(imageData)+" "+url);
image = fixGifFps(imageData);
} catch (Exception ex) {
/**
* If not a GIF, or another error occured, just create the image
* normally.
*/
image = new ImageIcon(imageData);
}
if (image.getImageLoadStatus() == MediaTracker.ERRORED) {
return null;
}
return image;
}
}
CustomButton.java 文件源码
项目:xdat
阅读 25
收藏 0
点赞 0
评论 0
/**
* Instantiates a new custom button.
*
* @param toolTip
* the message that is displayed when hovering over the button
* with the mouse.
* @param pathToDefaultImage
* the path to image representing the unpressed state of the
* button.
* @param pathToPressedImage
* the path to image representing the pressed state of the
* button.
* @param actionCommand
* the action command
*/
public CustomButton(String toolTip, String pathToDefaultImage, String pathToPressedImage, String actionCommand) {
super();
this.setToolTipText(toolTip);
URL urlDefault = Main.class.getResource(pathToDefaultImage);
URL urlPressed = Main.class.getResource(pathToPressedImage);
this.imgDefault = null;
this.imgPressed = null;
Toolkit tk = Toolkit.getDefaultToolkit();
try {
MediaTracker m = new MediaTracker(this);
this.imgDefault = tk.getImage(urlDefault);
m.addImage(this.imgDefault, 0);
this.imgPressed = tk.getImage(urlPressed);
m.addImage(this.imgPressed, 0);
m.waitForAll();
} catch (Exception e) {
e.printStackTrace();
}
// }
this.setActionCommand(actionCommand);
this.setLayout(new GridLayout(1, 1));
this.setPreferredSize(new Dimension(imgDefault.getWidth(this), imgDefault.getHeight(this)));
}
xtGraphics.java 文件源码
项目:OpenNFMM
阅读 20
收藏 0
点赞 0
评论 0
static private void loadimages() {
final Toolkit toolkit = Toolkit.getDefaultToolkit();
final MediaTracker mediatracker = new MediaTracker(app);
dnload += 8;
try {
for (int i = 0; i < idts.length; i++) {
idts[i].cons.accept(Files.readAllBytes(new File(Madness.fpath + "data/images/" + idts[i].fileName).toPath()), mediatracker, toolkit);
}
dnload += 2;
} catch (final Exception exception) {
System.err.println("Error Loading Images: " + exception);
}
System.gc();
}
Attachment.java 文件源码
项目:metasfresh
阅读 34
收藏 0
点赞 0
评论 0
/**
* Set Image
*
* @param image image
*/
public void setImage(final Image image)
{
m_image = image;
if (m_image == null)
return;
MediaTracker mt = new MediaTracker(this);
mt.addImage(m_image, 0);
try
{
mt.waitForID(0);
}
catch (Exception e)
{
}
Dimension dim = new Dimension(m_image.getWidth(this), m_image.getHeight(this));
this.setPreferredSize(dim);
}
GraphPlane.java 文件源码
项目:graphwar
阅读 18
收藏 0
点赞 0
评论 0
private void initializeDeaths(Graphwar graphwar, MediaTracker mediaTracker) throws Exception
{
String filePath = "/rsc/soldierDeath.txt";
BufferedReader read = new BufferedReader(new InputStreamReader(graphwar.getClass().getResourceAsStream(filePath)));
int numImages = Integer.parseInt(GraphUtil.nextLine(read).trim());
deathImages = new Image[numImages];
deathDurations = new int[numImages];
for(int j=0; j<numImages;j++)
{
deathImages[j] = ImageIO.read(graphwar.getClass().getResource(GraphUtil.nextLine(read)));
deathDurations[j] = Integer.parseInt(GraphUtil.nextLine(read).trim());
mediaTracker.addImage(deathImages[j], 0);
}
deathFadeDuration = Integer.parseInt(GraphUtil.nextLine(read).trim());
}
GraphPlane.java 文件源码
项目:graphwar
阅读 15
收藏 0
点赞 0
评论 0
private void initializeExplosions(Graphwar graphwar, MediaTracker mediaTracker) throws Exception
{
String filePath = "/rsc/explosion.txt";
BufferedReader read = new BufferedReader(new InputStreamReader(graphwar.getClass().getResourceAsStream(filePath)));
int numImages = Integer.parseInt(GraphUtil.nextLine(read).trim());
explosionImages = new Image[numImages];
explosionDurations = new int[numImages];
for(int j=0; j<numImages;j++)
{
explosionImages[j] = ImageIO.read(graphwar.getClass().getResource(GraphUtil.nextLine(read)));
explosionDurations[j] = Integer.parseInt(GraphUtil.nextLine(read).trim());
mediaTracker.addImage(explosionImages[j], 0);
}
}