當前位置: 首頁>>代碼示例>>Java>>正文


Java Image類代碼示例

本文整理匯總了Java中java.awt.Image的典型用法代碼示例。如果您正苦於以下問題:Java Image類的具體用法?Java Image怎麽用?Java Image使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。


Image類屬於java.awt包,在下文中一共展示了Image類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: copyImage

import java.awt.Image; //導入依賴的package包/類
/**
 * Not part of the advertised API but a useful utility method
 * to call internally.  This is for the case where we are
 * drawing to/from given coordinates using a given width/height,
 * but we guarantee that the surfaceData's width/height of the src and dest
 * areas are equal (no scale needed). Note that this method intentionally
 * ignore scale factor of the source image, and copy it as is.
 */
public boolean copyImage(Image img, int dx, int dy, int sx, int sy,
                         int width, int height, Color bgcolor,
                         ImageObserver observer) {
    try {
        return imagepipe.copyImage(this, img, dx, dy, sx, sy,
                                   width, height, bgcolor, observer);
    } catch (InvalidPipeException e) {
        try {
            revalidateAll();
            return imagepipe.copyImage(this, img, dx, dy, sx, sy,
                                       width, height, bgcolor, observer);
        } catch (InvalidPipeException e2) {
            // Still catching the exception; we are not yet ready to
            // validate the surfaceData correctly.  Fail for now and
            // try again next time around.
            return false;
        }
    } finally {
        surfaceData.markDirty();
    }
}
 
開發者ID:AdoptOpenJDK,項目名稱:openjdk-jdk10,代碼行數:30,代碼來源:SunGraphics2D.java

示例2: getDisabledIcon

import java.awt.Image; //導入依賴的package包/類
public static XBIcon getDisabledIcon(int which, boolean selected) {
	if( which<0 || which>=disIcons.length ) return getDefaultIcon(selected);
	int i = selected ? 1 : 0;
	if( disIcons[which][i]!=null )return disIcons[which][i];
	int i1 = (i+1)%2;
	if( disIcons[which][i1]!=null ) {
		disIcons[which][i] = new XBIcon(disIcons[which][i1].getImage(), selected);
		return disIcons[which][i];
	}

	try {
		if( loader==null ) {
			loader = org.geomapapp.util.Icons.class.getClassLoader();
		}
		String path = "org/geomapapp/resources/icons/" +names[which];
		java.net.URL url = loader.getResource(path);
		BufferedImage im = ImageIO.read(url);
		Image im1 = GrayFilter.createDisabledImage(im);
		Graphics g = im.createGraphics();
		g.drawImage(im1,0,0, new JPanel() );
		disIcons[which][i] = new XBIcon(im, selected);
	} catch(Exception ex) {
		return getDefaultIcon(selected);
	}
	return disIcons[which][i];
}
 
開發者ID:iedadata,項目名稱:geomapapp,代碼行數:27,代碼來源:Icons.java

示例3: waitForDimensions

import java.awt.Image; //導入依賴的package包/類
private synchronized void waitForDimensions(Image img) {
    mHeight = img.getHeight(this);
    mWidth = img.getWidth(this);
    while (!badImage && (mWidth < 0 || mHeight < 0)) {
        try {
            Thread.sleep(50);
        } catch(InterruptedException e) {
            // do nothing.
        }
        mHeight = img.getHeight(this);
        mWidth = img.getWidth(this);
    }
    if (badImage) {
        mHeight = 0;
        mWidth = 0;
    }
}
 
開發者ID:AdoptOpenJDK,項目名稱:openjdk-jdk10,代碼行數:18,代碼來源:PeekGraphics.java

示例4: SpriteManager

import java.awt.Image; //導入依賴的package包/類
public SpriteManager(String p, int tw, int th, int n,boolean l)
{
    loop = l;
    maxIms = n;
    index = 0;
    count = 0;
    delay = 10;

    currFrame = 0;
    ims = new Image[n];

    try
    {
        BufferedImage tIm = ImageIO.read(new File(p));            
        for (int i = 0; i < n; i++)
        {
            add(tIm.getSubimage(i*tw, 0, tw, th));
        }
    }
    catch(IOException e)
    {
        e.printStackTrace();
    }        
}
 
開發者ID:CoffeeCodeSwitzerland,項目名稱:Lernkartei_2017,代碼行數:25,代碼來源:SpriteManager.java

示例5: FrameBuilder

import java.awt.Image; //導入依賴的package包/類
FrameBuilder(Instance instance, Heap heap) {
    super(instance, heap);
    
    title = Utils.getFieldString(instance, "title");
    undecorated = DetailsUtils.getBooleanFieldValue(instance, "undecorated", false);
    
    Image _image = null;
    Object icons = instance.getValueOfField("icons");
    if (icons instanceof Instance) {
        Instance i = (Instance)icons;
        if (DetailsUtils.getIntFieldValue(i, "size", 0) > 0) {
            Object elementData = i.getValueOfField("elementData");
            if (elementData instanceof ObjectArrayInstance) {
                Object o = ((ObjectArrayInstance)elementData).getValues().get(0);
                _image = o != null ? ImageBuilder.buildImage((Instance)o, heap) : null;
            }
        }
    }
    image = _image;
}
 
開發者ID:apache,項目名稱:incubator-netbeans,代碼行數:21,代碼來源:WindowBuilders.java

示例6: readImage32

import java.awt.Image; //導入依賴的package包/類
protected static Image readImage32(FileInputStream fs, BitmapHeader bh) throws IOException {
	Image image;
	final int ndata[] = new int[bh.iHeight * bh.iWidth];
	final byte brgb[] = new byte[bh.iWidth * 4 * bh.iHeight];
	fs.read(brgb, 0, bh.iWidth * 4 * bh.iHeight);
	int nindex = 0;
	for (int j = 0; j < bh.iHeight; j++) {
		for (int i = 0; i < bh.iWidth; i++) {
			ndata[bh.iWidth * (bh.iHeight - j - 1) + i] = constructInt3(brgb, nindex);
			nindex += 4;
		}
	}
	image = Toolkit.getDefaultToolkit()
			.createImage(new MemoryImageSource(bh.iWidth, bh.iHeight, ndata, 0, bh.iWidth));
	fs.close();
	return (image);
}
 
開發者ID:zylo117,項目名稱:SpotSpotter,代碼行數:18,代碼來源:BMPReader.java

示例7: convertToBufferedImage

import java.awt.Image; //導入依賴的package包/類
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;
    }
}
 
開發者ID:AdoptOpenJDK,項目名稱:openjdk-jdk10,代碼行數:23,代碼來源:RuntimeBuiltinLeafInfoImpl.java

示例8: getIcon

import java.awt.Image; //導入依賴的package包/類
@Override
public Icon getIcon() {
    Node[] nodes = getNodes();
    if (nodes.length > 1) {
        return MULTI_SELECTION_ICON;
    } else if (nodes.length == 1 && nodes[0] != null) {
        Node n = nodes[0];
        Image image = n.getIcon(BeanInfo.ICON_COLOR_16x16);
        if (image != null) {
            return ImageUtilities.image2Icon(image);
        } else {
            return null;
        }
    } else {
        return null;
    }
}
 
開發者ID:apache,項目名稱:incubator-netbeans,代碼行數:18,代碼來源:SearchScopeNodeSelection.java

示例9: waitForDimensions

import java.awt.Image; //導入依賴的package包/類
synchronized private void waitForDimensions(Image img) {
    mHeight = img.getHeight(this);
    mWidth = img.getWidth(this);
    while (!badImage && (mWidth < 0 || mHeight < 0)) {
        try {
            Thread.sleep(50);
        } catch(InterruptedException e) {
            // do nothing.
        }
        mHeight = img.getHeight(this);
        mWidth = img.getWidth(this);
    }
    if (badImage) {
        mHeight = 0;
        mWidth = 0;
    }
}
 
開發者ID:lambdalab-mirror,項目名稱:jdk8u-jdk,代碼行數:18,代碼來源:PeekGraphics.java

示例10: getManager

import java.awt.Image; //導入依賴的package包/類
/**
 * Returns the SurfaceManager object contained within the given Image.
 */
public static SurfaceManager getManager(Image img) {
    SurfaceManager sMgr = imgaccessor.getSurfaceManager(img);
    if (sMgr == null) {
        /*
         * In practice only a BufferedImage will get here.
         */
        try {
            BufferedImage bi = (BufferedImage) img;
            sMgr = new BufImgSurfaceManager(bi);
            setManager(bi, sMgr);
        } catch (ClassCastException e) {
            throw new IllegalArgumentException("Invalid Image variant");
        }
    }
    return sMgr;
}
 
開發者ID:AdoptOpenJDK,項目名稱:openjdk-jdk10,代碼行數:20,代碼來源:SurfaceManager.java

示例11: annotateIcon

import java.awt.Image; //導入依賴的package包/類
@Override
@NonNull
public Image annotateIcon(
        @NonNull final Project p,
        @NonNull Image original,
        final boolean openedNode) {
    Boolean type = projectType.get(p);
    if (type != null) {
        if(type.booleanValue() == true) {
            final Image badge = getJFXBadge();
            if (badge != null) {
                original = ImageUtilities.mergeImages(original, badge, 8, 8);
            }
        }
    } else {
        evaluateProjectType(p);
    }
    return original;
}
 
開發者ID:apache,項目名稱:incubator-netbeans,代碼行數:20,代碼來源:JFXProjectIconAnnotator.java

示例12: readIconFromFile

import java.awt.Image; //導入依賴的package包/類
private Icon readIconFromFile( File iconFile ) {
    try {
        Image img = ImageIO.read( iconFile.toURL() );
        if( null != img ) {
            ImageIcon res = new ImageIcon( img );
            if( res.getIconWidth() > 32 || res.getIconHeight() > 32 )  {
                JOptionPane.showMessageDialog(this, NbBundle.getMessage(TextImporterUI.class, "Err_IconTooBig"), //NOI18N
                        NbBundle.getMessage(TextImporterUI.class, "Err_Title"), JOptionPane.ERROR_MESSAGE  ); //NOI18N
                return null;
            }
            return res;
        }
    } catch( ThreadDeath td ) {
        throw td;
    } catch( Throwable ioE ) {
        //ignore
    }
    JOptionPane.showMessageDialog(this, 
            NbBundle.getMessage(TextImporterUI.class, "Err_CannotLoadIconFromFile", iconFile.getName()), //NOI18N
            NbBundle.getMessage(TextImporterUI.class, "Err_Title"), JOptionPane.ERROR_MESSAGE  ); //NOI18N
    return null;
}
 
開發者ID:apache,項目名稱:incubator-netbeans,代碼行數:23,代碼來源:TextImporterUI.java

示例13: convertToPNG

import java.awt.Image; //導入依賴的package包/類
private static byte[] convertToPNG(Image image) {
   ByteArrayOutputStream out = new ByteArrayOutputStream();
   int width = image.getWidth(null);
   int height = image.getHeight(null);
   BufferedImage bi = new BufferedImage(width, height,
                                        BufferedImage.TYPE_INT_ARGB);
   Graphics2D g = bi.createGraphics();
   g.setComposite(AlphaComposite.Src);
   g.drawImage(image, 0, 0, null);
   g.dispose();
   ImageOutputStream ios = new MemoryCacheImageOutputStream(out);
   try {
      if (!ImageIO.write(bi, "PNG", ios)) {
         throw new IOException("ImageIO.write failed");
      }
      ios.close();
   } catch (IOException ex) {
      throw new RuntimeException("saveImage: " + ex.getMessage());
   }
   return out.toByteArray();
}
 
開發者ID:eric-roberts,項目名稱:JavaPPTX,代碼行數:22,代碼來源:PPPicture.java

示例14: getSystemIcon

import java.awt.Image; //導入依賴的package包/類
/**
 * Icon for a file, directory, or folder as it would be displayed in
 * a system file browser. Example from Windows: the "M:\" directory
 * displays a CD-ROM icon.
 *
 * The default implementation gets information from the ShellFolder class.
 *
 * @param f a <code>File</code> object
 * @return an icon as it would be displayed by a native file chooser
 * @see JFileChooser#getIcon
 * @since 1.4
 */
public Icon getSystemIcon(File f) {
    if (f == null) {
        return null;
    }

    ShellFolder sf;

    try {
        sf = getShellFolder(f);
    } catch (FileNotFoundException e) {
        return null;
    }

    Image img = sf.getIcon(false);

    if (img != null) {
        return new ImageIcon(img, sf.getFolderType());
    } else {
        return UIManager.getIcon(f.isDirectory() ? "FileView.directoryIcon" : "FileView.fileIcon");
    }
}
 
開發者ID:SunburstApps,項目名稱:OpenJSharp,代碼行數:34,代碼來源:FileSystemView.java

示例15: getProperty

import java.awt.Image; //導入依賴的package包/類
/**
 * Return a property of the image by name.  Individual property names
 * are defined by the various image formats.  If a property is not
 * defined for a particular image, then this method will return the
 * UndefinedProperty object.  If the properties for this image are
 * not yet known, then this method will return null and the ImageObserver
 * object will be notified later.  The property name "comment" should
 * be used to store an optional comment which can be presented to
 * the user as a description of the image, its source, or its author.
 */
public Object getProperty(String name, ImageObserver observer) {
    if (name == null) {
        throw new NullPointerException("null property name is not allowed");
    }

    if (src != null) {
        src.checkSecurity(null, false);
    }
    if (properties == null) {
        addWatcher(observer, true);
        if (properties == null) {
            return null;
        }
    }
    Object o = properties.get(name);
    if (o == null) {
        o = Image.UndefinedProperty;
    }
    return o;
}
 
開發者ID:lambdalab-mirror,項目名稱:jdk8u-jdk,代碼行數:31,代碼來源:ToolkitImage.java


注:本文中的java.awt.Image類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。