本文整理匯總了Java中javax.swing.ImageIcon.paintIcon方法的典型用法代碼示例。如果您正苦於以下問題:Java ImageIcon.paintIcon方法的具體用法?Java ImageIcon.paintIcon怎麽用?Java ImageIcon.paintIcon使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類javax.swing.ImageIcon
的用法示例。
在下文中一共展示了ImageIcon.paintIcon方法的3個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: setBackgroundImage
import javax.swing.ImageIcon; //導入方法依賴的package包/類
public void setBackgroundImage(Image image) {
if (image != null) {
final ImageIcon icon = new ImageIcon(image);
logoSize = new Dimension(icon.getIconWidth(), icon.getIconHeight());
final BufferedImage img =
ImageUtils.createCompatibleTranslucentImage(logoSize.width,
logoSize.height);
Graphics2D g = img.createGraphics();
g.setColor(Color.white);
g.fillRect(0, 0, icon.getIconWidth(), icon.getIconHeight());
g.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC_OVER, 0.5F));
icon.paintIcon(null, g, 0, 0);
g.dispose();
UIManager.put("wizard.sidebar.image", img); //$NON-NLS-1$
}
}
示例2: serialize
import javax.swing.ImageIcon; //導入方法依賴的package包/類
@Override
public void serialize(ImageIcon vi, JsonGenerator jgen, SerializerProvider provider)
throws IOException, JsonProcessingException {
synchronized (vi) {
BufferedImage v = new BufferedImage(
vi.getIconWidth(),
vi.getIconHeight(),
BufferedImage.TYPE_INT_RGB);
Graphics g = v.createGraphics();
// paint the Icon to the BufferedImage.
vi.paintIcon(null, g, 0, 0);
g.dispose();
ByteArrayOutputStream baos = new ByteArrayOutputStream();
ImageIO.write(v, "png", baos);
byte [] data = baos.toByteArray();
jgen.writeStartObject();
jgen.writeStringField("type", "ImageIcon");
jgen.writeObjectField("imageData", data);
jgen.writeNumberField("width", v.getWidth());
jgen.writeNumberField("height", v.getHeight());
jgen.writeEndObject();
}
}
示例3: toBufferedImage
import javax.swing.ImageIcon; //導入方法依賴的package包/類
public static BufferedImage toBufferedImage(final ImageIcon icon) {
if (icon == null) return null;
final int w = icon.getIconWidth(), h = icon.getIconHeight();
final BufferedImage bi = new BufferedImage(w, h, BufferedImage.TYPE_INT_ARGB);
final Graphics g = bi.createGraphics();
icon.paintIcon(null, g, 0,0);
g.dispose();
return bi;
}