当前位置: 首页>>代码示例>>Java>>正文


Java Component.createImage方法代码示例

本文整理汇总了Java中java.awt.Component.createImage方法的典型用法代码示例。如果您正苦于以下问题:Java Component.createImage方法的具体用法?Java Component.createImage怎么用?Java Component.createImage使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在java.awt.Component的用法示例。


在下文中一共展示了Component.createImage方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: createCompImage

import java.awt.Component; //导入方法依赖的package包/类
private Image createCompImage(Component comp, Dimension targetSize) {
    // component won't paint if not showing anyway, so don't create
    // empty image but honestly return null 
    if (!comp.isShowing()) {
        return null;
    }
    
    Image image = comp.createImage(comp.getWidth(), comp.getHeight());
    
    /*BufferedImage image = GraphicsEnvironment.getLocalGraphicsEnvironment().
            getDefaultScreenDevice().getDefaultConfiguration().
            createCompatibleImage(comp.getWidth(), comp.getHeight());*/
    //BufferedImage image = new BufferedImage (targetSize.width, targetSize.height, BufferedImage.TYPE_INT_RGB);
    
    Graphics2D gr2d = (Graphics2D)image.getGraphics();
    
    comp.paint(gr2d);
    
    gr2d.dispose();
    
    return image;
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:23,代码来源:ScaleFx.java

示例2: getOffscreenEquivalent

import java.awt.Component; //导入方法依赖的package包/类
/**
 * For the given input color, return the color that this color
 * will map to in an offscreen image created by the given Component
 */
public static int getOffscreenEquivalent(int color, Component obs) {
  Image im = obs.createImage(1, 1);
  Graphics2D g = (Graphics2D) im.getGraphics();
  g.setColor(new java.awt.Color(color));
  g.fillRect(0, 0, 1, 1);
  g.dispose();

  int[] bg = new int[1];
  PixelGrabber pg = new PixelGrabber(im, 0, 0, 1, 1, bg, 0, 1);
  try {
    pg.grabPixels();
  }
  catch (InterruptedException ex) {
    logger.error("", ex);
  }
  return bg[0];
}
 
开发者ID:ajmath,项目名称:VASSAL-src,代码行数:22,代码来源:TransparentFilter.java

示例3: checkCreateImage

import java.awt.Component; //导入方法依赖的package包/类
private static void checkCreateImage(final Component comp,
                                     final boolean isNull) {
    if ((comp.createImage(10, 10) != null) == isNull) {
        throw new RuntimeException("Image is wrong");
    }
    if ((comp.createVolatileImage(10, 10) != null) == isNull) {
        throw new RuntimeException("Image is wrong");
    }
    try {
        if ((comp.createVolatileImage(10, 10, null) != null) == isNull) {
            throw new RuntimeException("Image is wrong");
        }
    } catch (final AWTException ignored) {
        // this check is not applicable
    }
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:17,代码来源:CreateImage.java

示例4: makeTransparent

import java.awt.Component; //导入方法依赖的package包/类
private static Image makeTransparent(Component c, Image workingImage) {
    int[] array =
            getPixels(workingImage, 0, 0, workingImage.getWidth(c), workingImage.getHeight(c));

    for (int i = 0; i < array.length; i++) {
        array[i] = makeWhiteTransparent(array[i]);
    }

    MemoryImageSource source = new MemoryImageSource(workingImage.getWidth(c),
                                                     workingImage.getHeight(c),
                                                     array,
                                                     0,
                                                     workingImage.getWidth(c));
    return c.createImage(source);
}
 
开发者ID:addertheblack,项目名称:myster,代码行数:16,代码来源:TabUtilities.java

示例5: draw

import java.awt.Component; //导入方法依赖的package包/类
public void draw(Graphics g, int x, int y, Component obs, double zoom) {
    if (alpha == 1.0) {
      piece.draw(g, x, y, obs, zoom);
      return;
    }
    if (opaque.isChanged()) {

      int trans = VASSAL.tools.TransparentFilter.getOffscreenEquivalent(obs.getBackground().getRGB(), obs);
      VASSAL.tools.TransparentFilter filter = new VASSAL.tools.TransparentFilter();
      filter.setAlpha(alpha);
      filter.setAlpha(0.0, trans);
      im = opaque.getImage(obs);
      Image im2 = obs.createImage(im.getWidth(obs), im.getHeight(obs));
      Graphics2D gg = (Graphics2D) im2.getGraphics();
      gg.drawImage(im, 0, 0, obs);
      gg.dispose();
      im = obs.createImage(new FilteredImageSource
        (im2.getSource(), filter));
      offset = new Point(piece.boundingBox().x,
                         piece.boundingBox().y);

/*
      im = opaque.getImage(obs);
      final Image im2 = obs.createImage(im.getWidth(obs), im.getHeight(obs));
      final Graphics2D gg = (Graphics2D) im2.getGraphics();
      gg.setComposite(
        AlphaComposite.getInstance(AlphaComposite.SRC_OVER, (float) alpha));
      gg.drawImage(im, 0, 0, obs);
      gg.dispose();

      offset = new Point(piece.boundingBox().x,
                         piece.boundingBox().y);
*/
    }

    Image scaled = im;
    if (zoom != 1.0) {
      scaled = GameModule.getGameModule().getDataArchive().getScaledImage(im,zoom);
    }
    g.drawImage(scaled,
                x + (int) (zoom * offset.x),
                y + (int) (zoom * offset.y),
                obs);
  }
 
开发者ID:ajmath,项目名称:VASSAL-src,代码行数:45,代码来源:Transparent.java


注:本文中的java.awt.Component.createImage方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。