Java 类java.awt.image.BufferedImage 实例源码

项目:openjdk-jdk10    文件:JMenuItemsTest.java   
private void testDisabledStateOfJMenu() {

        // Test disabled JMenu state
        Rectangle rect = disabledMenu.getBounds();
        BufferedImage image = new BufferedImage(rect.width, rect.height,
                BufferedImage.TYPE_INT_ARGB);
        disabledMenu.paint(image.getGraphics());
        int y = image.getHeight() / 2;
        for (int x = 0; x < image.getWidth(); x++) {
            Color c = new Color(image.getRGB(x, y));
            if (c.equals(Color.BLUE)) {
                dispose();
                throw new RuntimeException("JMenu Disabled"
                        + " State not Valid.");
            }
        }

    }
项目:freecol    文件:ImageLibrary.java   
public static BufferedImage getUnitImage(UnitType unitType, String roleId,
                                         boolean nativeEthnicity,
                                         Dimension size) {
    // units that can only be native don't need the .native key part
    if (unitType.hasAbility(Ability.BORN_IN_INDIAN_SETTLEMENT)) {
        nativeEthnicity = false;
    }

    // try to get an image matching the key
    String roleQual = (Role.isDefaultRoleId(roleId)) ? ""
        : "." + Role.getRoleSuffix(roleId);
    String key = "image.unit." + unitType.getId() + roleQual
        + ((nativeEthnicity) ? ".native" : "");
    if (!ResourceManager.hasImageResource(key) && nativeEthnicity) {
        key = "image.unit." + unitType.getId() + roleQual;
    }
    BufferedImage image = ResourceManager.getImage(key, size);
    return image;
}
项目:openjdk-jdk10    文件:OnScreenRenderingResizeTest.java   
private static void checkBI(BufferedImage bi, int accepted[]) {
    for (int x = 0; x < bi.getWidth(); x++) {
        for (int y = 0; y < bi.getHeight(); y++) {
            int pix = bi.getRGB(x, y);
            boolean found = false;
            for (int acc : accepted) {
                if (pix == acc) {
                    found = true;
                    break;
                }
            }
            if (!found) {
                try {
                    String name = "OnScreenRenderingResizeTest.png";
                    ImageIO.write(bi, "png", new File(name));
                    System.out.println("Screen shot file: " + name);
                } catch (IOException ex) {}

                throw new
                    RuntimeException("Test failed at " + x + "-" + y +
                                     " rgb=0x" + Integer.toHexString(pix));
            }
        }
    }
}
项目:jdk8u-jdk    文件:BufImgSurfaceData.java   
public static SurfaceData createDataBP(BufferedImage bImg,
                                       SurfaceType sType) {
    BytePackedRaster bpRaster =
        (BytePackedRaster)bImg.getRaster();
    BufImgSurfaceData bisd =
        new BufImgSurfaceData(bpRaster.getDataBuffer(), bImg, sType);
    ColorModel cm = bImg.getColorModel();
    IndexColorModel icm = ((cm instanceof IndexColorModel)
                           ? (IndexColorModel) cm
                           : null);
    bisd.initRaster(bpRaster.getDataStorage(),
                    bpRaster.getDataBitOffset() / 8,
                    bpRaster.getDataBitOffset() & 7,
                    bpRaster.getWidth(),
                    bpRaster.getHeight(),
                    0,
                    bpRaster.getScanlineStride(),
                    icm);
    return bisd;
}
项目:G2Dj    文件:Resources.java   
public static final Image loadImage(final String aFileName)
{
    Debug.log(aFileName);
    String name = aFileName.substring(aFileName.lastIndexOf('/') + 1);
    String path = sanitizeFilePath(aFileName);

    //.if DESKTOP
    BufferedImage data = null;
    try{data=ImageIO.read(Resources.class.getResource(path));}
    catch (IOException ex) {Logger.getLogger(Resources.class.getName()).log(Level.SEVERE, null, ex);}
    //.elseif ANDROID
    //|android.graphics.Bitmap data = null;
    //|Debug.log("Resources.loadImage*********************************");
    //|Debug.log(path);

    //|InputStream dataStream = Mobile.loadAsset(path);

    //|data = BitmapFactory.decodeStream(dataStream);

    //|Debug.log(data.getByteCount());

    //.endif

    return new Image(name,data);

}
项目:OutsourcedProject    文件:ImageUtil.java   
/**
 *
 * @param bi
 * @param nw
 * @param nh
 * @param tarFile
 * @return boolean
 * @Title: compressAndSave
 * @Description: 压缩处理
 */
public static boolean compressAndSave(BufferedImage bi, int nw, int nh,
                                      File tarFile) {
    try {
        BufferedImage destImage = resize(bi, nw, nh);
        // 输出文件
        String fileName = tarFile.getName();
        String formatName = fileName
                .substring(fileName.lastIndexOf('.') + 1);
        ImageIO.write(destImage, formatName, tarFile);
        return true;
    } catch (Exception e) {
        log.error(ExceptionMessage.IO_EXCEPTION.getExceptionMsg());
        return false;
    }
}
项目:SpriteAnimator    文件:AnimatedGIFWriter.java   
public GIFFrame(BufferedImage frame, int leftPosition, int topPosition, int delay, int disposalMethod, int userInputFlag, int transparencyFlag, int transparentColor) {
    if(frame == null) throw new IllegalArgumentException("Null input image");
    if(disposalMethod < DISPOSAL_UNSPECIFIED || disposalMethod > DISPOSAL_TO_BE_DEFINED)
        throw new IllegalArgumentException("Invalid disposal method: " + disposalMethod);
    if(userInputFlag < USER_INPUT_NONE || userInputFlag > USER_INPUT_EXPECTED)
        throw new IllegalArgumentException("Invalid user input flag: " + userInputFlag);
    if(transparencyFlag < TRANSPARENCY_INDEX_NONE || transparencyFlag > TRANSPARENCY_INDEX_SET)
        throw new IllegalArgumentException("Invalid transparency flag: " + transparencyFlag);
    if(leftPosition < 0 || topPosition < 0)
        throw new IllegalArgumentException("Negative coordinates for frame top-left position");
    if(delay < 0) delay = 0;
    this.frame = frame;
    this.leftPosition = leftPosition;
    this.topPosition = topPosition;
    this.delay = delay;
    this.disposalMethod = disposalMethod;
    this.userInputFlag = userInputFlag;
    this.transparencyFlag = transparencyFlag;
    this.frameWidth = frame.getWidth();
    this.frameHeight = frame.getHeight();
    this.transparentColor = transparentColor;
}
项目:OutsourcedProject    文件:ImageUtil.java   
/**
 * @param is
 * @param deistPath
 * @param newWidth
 * @param newHeight
 * @return int
 * @Title: saveCompress
 * @Description: 压缩图片,统一压缩成JPG格式,返回压缩后的大小(字节)
 */
public static int saveCompress(InputStream is, String deistPath,
                               int newWidth, int newHeight) {
    try {
        BufferedImage srcImage = ImageIO.read(is);
        BufferedImage destImage = resize(srcImage, newWidth, newHeight);
        File deistFile = new File(deistPath);
        String fileName = deistFile.getName();
        String formatName = fileName
                .substring(fileName.lastIndexOf('.') + 1);
        ImageIO.write(destImage, formatName, deistFile);
        return (int) deistFile.length();
    } catch (Exception e) {
        return -1;
    }
}
项目:jdk8u-jdk    文件:D3DBlitLoops.java   
@Override
public synchronized void Transform(SurfaceData src, SurfaceData dst,
                                   Composite comp, Region clip,
                                   AffineTransform at, int hint, int srcx,
                                   int srcy, int dstx, int dsty, int width,
                                   int height){
    Blit convertsrc = Blit.getFromCache(src.getSurfaceType(),
                                        CompositeType.SrcNoEa,
                                        SurfaceType.IntArgbPre);
    // use cached intermediate surface, if available
    final SurfaceData cachedSrc = srcTmp != null ? srcTmp.get() : null;
    // convert source to IntArgbPre
    src = convertFrom(convertsrc, src, srcx, srcy, width, height, cachedSrc,
                      BufferedImage.TYPE_INT_ARGB_PRE);

    // transform IntArgbPre intermediate surface to D3D surface
    performop.Transform(src, dst, comp, clip, at, hint, 0, 0, dstx, dsty,
                        width, height);

    if (src != cachedSrc) {
        // cache the intermediate surface
        srcTmp = new WeakReference<>(src);
    }
}
项目:openjdk-jdk10    文件:ImageWriterCompressionTest.java   
private static long saveImage(final BufferedImage image,
                              final ImageWriter writer,
                              final ImageWriteParam writerParams,
                              final String mode,
                              final String suffix) throws IOException
{
    final File imgFile = new File("WriterCompressionTest-"
                                  + mode + '.' + suffix);
    System.out.println("Writing file: " + imgFile.getAbsolutePath());

    final ImageOutputStream imgOutStream
        = ImageIO.createImageOutputStream(new FileOutputStream(imgFile));
    try {
        writer.setOutput(imgOutStream);
        writer.write(null, new IIOImage(image, null, null), writerParams);
    } finally {
        imgOutStream.close();
    }
    return imgFile.length();
}
项目:VTerminal    文件:FontLoader.java   
/**
 * Processes a font sprite sheet and character data into a usable HashMap of
 * character sprites.
 *
 * @param spriteSheet
 *         The sprite sheet.
 *
 * @param characterData
 *         The character data.
 *
 * @return
 *         The HashMap of character sprites.
 *
 * @throws NullPointerException
 *         If the sprite sheet or character data is null.
 */
private static HashMap<Character, BufferedImage> processFontData(final @NonNull BufferedImage spriteSheet, final @NonNull List<String> characterData) {
    final HashMap<Character, BufferedImage> hashMap = new HashMap<>(characterData.size());

    for (final String string : characterData) {
        if (string.isEmpty() == false) {
            final Scanner scanner = new Scanner(string);
            final char character = (char) scanner.nextInt();

            final int x = scanner.nextInt();
            final int y = scanner.nextInt();
            final int width = scanner.nextInt();
            final int height = scanner.nextInt();
            final BufferedImage image = spriteSheet.getSubimage(x, y, width, height);

            hashMap.put(character, image);
        }
    }

    return hashMap;
}
项目:openjdk-jdk10    文件:UserPluginMetadataFormatTest.java   
public  void processThumbnailUpdate(BufferedImage theThumbnail,
                                    int minX,
                                    int minY,
                                    int width,
                                    int height,
                                    int periodX,
                                    int periodY,
                                    int[] bands) {
    super.processThumbnailUpdate(theThumbnail,
                                 minX,
                                 minY,
                                 width,
                                 height,
                                 periodX,
                                 periodY,
                                 bands);
}
项目:openjdk-jdk10    文件:EncodeSubImageTest.java   
public static void main(String[] args) throws IOException {
    if (args.length > 0) {
        format = args[0];
    }

    writer = ImageIO.getImageWritersByFormatName(format).next();

    file_suffix =writer.getOriginatingProvider().getFileSuffixes()[0];

    BufferedImage src = createTestImage();
    EncodeSubImageTest m1 = new EncodeSubImageTest(src);
    m1.doTest("test_src");

    BufferedImage sub = src.getSubimage(subImageOffset, subImageOffset,
            src.getWidth() - 2 * subImageOffset,
            src.getHeight() - 2 * subImageOffset);
    EncodeSubImageTest m2 = new EncodeSubImageTest(sub);
    m2.doTest("test_sub");
}
项目:jdk8u-jdk    文件:DrawRotatedString.java   
private static BufferedImage createBufferedImage(final boolean  aa) {
    final BufferedImage bi = new BufferedImage(SIZE, SIZE,
                                               BufferedImage.TYPE_INT_RGB);
    final Graphics2D bg = bi.createGraphics();
    bg.setRenderingHint(RenderingHints.KEY_ANTIALIASING,
                        aa ? RenderingHints.VALUE_ANTIALIAS_ON
                           : RenderingHints.VALUE_ANTIALIAS_OFF);
    bg.setColor(Color.RED);
    bg.fillRect(0, 0, SIZE, SIZE);
    bg.translate(100, 100);
    bg.rotate(Math.toRadians(90));
    bg.setColor(Color.BLACK);
    bg.setFont(bg.getFont().deriveFont(20.0f));
    bg.drawString("MMMMMMMMMMMMMMMM", 0, 0);
    bg.dispose();
    return bi;
}
项目:hearthstone    文件:Img.java   
/**
 * Salva uma imagem .png com o printscreen da tela atual
 *
 * @param file local a ser salva a imagem
 * @return {@code true} para imagem salva. {@code false} para erro ao salvar
 * imagem.
 */
public static boolean printScreen(File file) {
    try {
        Robot robot = new Robot();
        Toolkit toolkit = Toolkit.getDefaultToolkit();
        Dimension d = toolkit.getScreenSize();
        BufferedImage bi = robot.createScreenCapture(new Rectangle(0, 0, d.width, d.height));
        ImageIO.write(bi, "PNG", file);
        return true;
    } catch (Exception ex) {
        return false;
    }
}
项目:jdk8u-jdk    文件:IncorrectUnmanagedImageRotatedClip.java   
private static BufferedImage makeUnmanagedBI() {
    final BufferedImage bi = new BufferedImage(500, 200, TYPE_INT_ARGB);
    final DataBuffer db = bi.getRaster().getDataBuffer();
    if (db instanceof DataBufferInt) {
        ((DataBufferInt) db).getData();
    } else if (db instanceof DataBufferShort) {
        ((DataBufferShort) db).getData();
    } else if (db instanceof DataBufferByte) {
        ((DataBufferByte) db).getData();
    } else {
        try {
            bi.setAccelerationPriority(0.0f);
        } catch (final Throwable ignored) {
        }
    }
    return bi;
}
项目:VASSAL-src    文件:ImageUtils.java   
public static BufferedImage toCompatibleImage(BufferedImage src) {
  if ((src.getColorModel().equals(compatOpaqueImage.getColorModel()) &&
       src.getTransparency() == compatOpaqueImage.getTransparency())
      ||
      (src.getColorModel().equals(compatTransImage.getColorModel()) &&
       src.getTransparency() == compatTransImage.getTransparency()))
  {
    return src;
  }

  final BufferedImage dst = createCompatibleImage(
    src.getWidth(), src.getHeight(), isTransparent(src)
  );

  final Graphics2D g = dst.createGraphics();
  g.drawImage(src, 0, 0, null);
  g.dispose();

  return dst;
}
项目:FreeCol    文件:MapViewer.java   
/**
 * Draw the unit's image and occupation indicator in one JLabel object.
 *
 * @param unit The unit to be drawn
 * @return A JLabel object with the unit's image.
 */
private JLabel createUnitLabel(Unit unit) {
    final BufferedImage unitImg = lib.getUnitImage(unit);
    final int width = halfWidth + unitImg.getWidth()/2;
    final int height = unitImg.getHeight();

    BufferedImage img = new BufferedImage(width, height,
                                          BufferedImage.TYPE_INT_ARGB);
    Graphics2D g = img.createGraphics();

    final int unitX = (width - unitImg.getWidth()) / 2;
    g.drawImage(unitImg, unitX, 0, null);

    Player player = getMyPlayer();
    String text = Messages.message(unit.getOccupationLabel(player, false));
    g.drawImage(lib.getOccupationIndicatorChip(g, unit, text), 0, 0, null);

    final JLabel label = new JLabel(new ImageIcon(img));
    label.setSize(width, height);

    g.dispose();
    return label;
}
项目:VASSAL-src    文件:MemoryImageTypeConverterTest.java   
@Test
public void testConvert() throws IOException {
  final BufferedImage src = ImageIO.read(new File(test));
  final ImageTypeConverter c = new MemoryImageTypeConverter();
  final Reference<BufferedImage> ref = new Reference<BufferedImage>(src);
  final BufferedImage dst = c.convert(ref, BufferedImage.TYPE_INT_ARGB);
  assertImageContentEquals(src, dst);
}
项目:The-Mysterious-Mind-Of-Jack    文件:Tools.java   
public static BufferedImage getImage(String file) {
      BufferedImage image = null;
if (images.containsKey(file)) image = images.get(file);
else {
       try {
           image = ImageIO.read(Tools.class.getResourceAsStream(file));
       } catch (Exception e) {
           e.printStackTrace();
       }
}
      return image;
  }
项目:BHBot    文件:MainThread.java   
public static BufferedImage loadImage(String f) {
    BufferedImage img = null;
    try {
        img = ImageIO.read(new File(f));
    } catch (IOException e) {
        e.printStackTrace();
    }
    return img;
}
项目:openjdk-jdk10    文件:OffScreenImageSource.java   
public OffScreenImageSource(BufferedImage image,
                            Hashtable<?, ?> properties) {
    this.image = image;
    if (properties != null) {
        this.properties = properties;
    } else {
        this.properties = new Hashtable<String, Object>();
    }
    width  = image.getWidth();
    height = image.getHeight();
}
项目:openjdk-jdk10    文件:DrawRotatedStringUsingRotatedFont.java   
/**
 * Compares two images.
 */
private static void compareImage(final BufferedImage bi1,
                                 final BufferedImage bi2)
        throws IOException {
    for (int i = 0; i < SIZE; ++i) {
        for (int j = 0; j < SIZE; ++j) {
            if (bi1.getRGB(i, j) != bi2.getRGB(i, j)) {
                ImageIO.write(bi1, "png", new File("image1.png"));
                ImageIO.write(bi2, "png", new File("image2.png"));
                throw new RuntimeException("Failed: wrong text location");
            }
        }
    }
}
项目:VTerminal    文件:CharGlowShader.java   
@Override
public BufferedImage run(final @NonNull BufferedImage image, final @NonNull AsciiCharacter character) {
    if (character instanceof AsciiTile) {
        return image;
    }

    if (character.isForegroundAndBackgroundColorEqual()) {
        return image;
    }

    // Get character image:
    final BufferedImage charImage = swapColor(image, character.getBackgroundColor(), new Color(0, 0, 0, 0));

    // Generate glow image:
    final GaussianFilter filter = new GaussianFilter();
    filter.setRadius(5);
    final BufferedImage glowImage = filter.filter(charImage, null);

    // Combine images and background:
    final BufferedImage result = new BufferedImage(image.getWidth(), image.getHeight(), BufferedImage.TYPE_INT_ARGB);
    final Graphics2D gc = (Graphics2D) result.getGraphics();

    gc.setColor(character.getBackgroundColor());
    gc.fillRect(0, 0, result.getWidth(), result.getHeight());
    gc.drawImage(glowImage, 0, 0, null);
    gc.drawImage(charImage, 0, 0, null);
    gc.dispose();

    return result;
}
项目:JAVA-    文件:ImageUtil.java   
/**
 * 根据宽度同比缩放
 * 
 * @param orgImg 源图片
 * @param orgWidth 原始宽度
 * @param targetWidth 缩放后的宽度
 * @param targetFile 缩放后的图片存放路径
 * @throws IOException
 */
public static final double scaleWidth(BufferedImage orgImg, int targetWidth, String targetFile) throws IOException {
    int orgWidth = orgImg.getWidth();
    // 计算宽度的缩放比例
    double scale = targetWidth * 1.00 / orgWidth;
    // 裁剪
    scale(orgImg, scale, targetFile);

    return scale;
}
项目:QN-ACTR-Release    文件:PAResultsWindow.java   
BufferedImage convertType(BufferedImage src, int targetType) {
    if (src.getType() == targetType) {
        return src;
    }
    BufferedImage tgt = new BufferedImage(src.getWidth(), src.getHeight(), targetType);
    Graphics2D g = tgt.createGraphics();
    g.drawRenderedImage(src, null);
    g.dispose();
    return tgt;
}
项目:ImageEnhanceViaFusion    文件:ImShow.java   
public BufferedImage toBufferedImage(Mat m) {
    int type = BufferedImage.TYPE_BYTE_GRAY;
    if (m.channels() > 1) {
        type = BufferedImage.TYPE_3BYTE_BGR;
    }
    int bufferSize = m.channels() * m.cols() * m.rows();
    byte[] b = new byte[bufferSize];
    m.get(0, 0, b); // get all the pixels
    BufferedImage image = new BufferedImage(m.cols(), m.rows(), type);
    final byte[] targetPixels = ((DataBufferByte) image.getRaster().getDataBuffer()).getData();
    System.arraycopy(b, 0, targetPixels, 0, b.length);
    return image;

}
项目:parabuild-ci    文件:BarChart3DTests.java   
/**
 * Draws the chart with a null info object to make sure that no exceptions are thrown (a
 * problem that was occurring at one point).
 */
public void testDrawWithNullInfo() {
    boolean success = false;
    try {
        BufferedImage image = new BufferedImage(200 , 100, BufferedImage.TYPE_INT_RGB);
        Graphics2D g2 = image.createGraphics();
        this.chart.draw(g2, new Rectangle2D.Double(0, 0, 200, 100), null, null);
        g2.dispose();
        success = true;
    }
    catch (Exception e) {
        success = false;
    }
    assertTrue(success);
}
项目:jmt    文件:EnlargePDF.java   
BufferedImage convertType(BufferedImage src, int targetType) {
    if (src.getType() == targetType) {
        return src;
    }
    BufferedImage tgt = new BufferedImage(src.getWidth(), src.getHeight(), targetType);
    Graphics2D g = tgt.createGraphics();
    g.drawRenderedImage(src, null);
    g.dispose();
    return tgt;
}
项目:VASSAL-src    文件:TileSlicerImpl.java   
protected static void queueTileTasks(
  BufferedImage src,
  String iname,
  String tpath,
  int div,
  int tw,
  int th,
  int dw,
  int dh,
  TaskMaker tm,
  ExecutorService exec,
  List<Future<Void>> futures
)
{
  final int tcols = (int) Math.ceil((double) dw / tw);
  final int trows = (int) Math.ceil((double) dh / th);

  for (int tx = 0; tx < tcols; ++tx) {
    for (int ty = 0; ty < trows; ++ty) {
      final String tn = TileUtils.tileName(iname, tx, ty, div);
      final File f = new File(tpath, tn);

      final TileTask tt = tm.make(src, f, tx, ty, tw, th, dw, dh);
      futures.add(exec.submit(tt));
    }
  }
}
项目:VASSAL-src    文件:PieceMover.java   
private BufferedImage featherDragImage(BufferedImage src,
                                           int w, int h, int b) {
// FIXME: This should be redone so that we draw the feathering onto the
// destination first, and then pass the Graphics2D on to draw the pieces
// directly over it. Presently this doesn't work because some of the
// pieces screw up the Graphics2D when passed it... The advantage to doing
// it this way is that we create only one BufferedImage instead of two.
      final BufferedImage dst =
        ImageUtils.createCompatibleTranslucentImage(w, h);

      final Graphics2D g = dst.createGraphics();
      g.setRenderingHint(RenderingHints.KEY_ANTIALIASING,
                         RenderingHints.VALUE_ANTIALIAS_ON);

      // paint the rectangle occupied by the piece at specified alpha
      g.setColor(new Color(0xff, 0xff, 0xff, CURSOR_ALPHA));
      g.fillRect(0, 0, w, h);

      // feather outwards
      for (int f = 0; f < b; ++f) {
        final int alpha = CURSOR_ALPHA * (f + 1) / b;
        g.setColor(new Color(0xff, 0xff, 0xff, alpha));
        g.drawRect(f, f, w-2*f, h-2*f);
      }

      // paint in the source image
      g.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC_IN));
      g.drawImage(src, 0, 0, null);
      g.dispose();

      return dst;
    }
项目:openjdk-jdk10    文件:BitDepth.java   
private File testWriteRGB(String format, int type) throws IOException {

        BufferedImage bi = new BufferedImage(width, height, type);
        Graphics2D g = bi.createGraphics();

        Color white = new Color(255, 255, 255);
        Color red = new Color(255, 0, 0);
        Color green = new Color(0, 255, 0);
        Color blue = new Color(0, 0, 255);

        g.setColor(white);
        g.fillRect(0, 0, width, height);
        g.setColor(red);
        g.fillRect(10, 10, 20, 20);
        g.setColor(green);
        g.fillRect(30, 30, 20, 20);
        g.setColor(blue);
        g.fillRect(50, 50, 20, 20);

        ImageTypeSpecifier spec = new ImageTypeSpecifier(bi);
        Iterator<ImageWriter> writers = ImageIO.getImageWriters(spec, format);
        File file = new File("BitDepth_" + biTypeNames[type] + "." + format);
        if (!writers.hasNext()) {
            System.out.println("\tNo writers available for type " + biTypeNames[type]
                               + " BufferedImage!");
        } else {
            ImageWriter writer = writers.next();
            try (ImageOutputStream out = ImageIO.createImageOutputStream(file)) {
                writer.setOutput(out);
                writer.write(bi);
            } catch (Exception e) {
                System.out.println("\tCan't write a type " +  biTypeNames[type]
                           + " BufferedImage!");
                return null;
            }
        }

        return file;
    }
项目:geomapapp    文件:Digitizer.java   
void saveProfile(String fmt) {

    JFileChooser chooser = MapApp.getFileChooser();
    String defaultFileName = list.getSelectedValue().toString().replace(" ", "_") + "." + fmt;
    chooser.setSelectedFile(new File(defaultFileName));
    int ok = chooser.showSaveDialog(map.getTopLevelAncestor());
    if( ok==JFileChooser.CANCEL_OPTION ) return;
    File file = chooser.getSelectedFile();
    if( file.exists() ) {
        ok = askOverWrite();
        if( ok==JOptionPane.CANCEL_OPTION ) return;
    }

    //get the image from the graph
    BufferedImage image = graph.getFullImage();
    Graphics g = image.getGraphics();
    graph.paint(g);

    try {
        String name = file.getName();
        int sIndex = name.lastIndexOf(".");
        String suffix = sIndex<0
            ? fmt
            : name.substring( sIndex+1 );
        if( !ImageIO.getImageWritersBySuffix(suffix).hasNext())suffix = fmt;

        if ( chooser.getSelectedFile().getPath().endsWith(fmt) ) {
            ImageIO.write(image, suffix, file);
        }
        else {
            ImageIO.write(image, suffix, new File(file.getPath() + fmt) );
        }

    } catch(IOException e) {
        JOptionPane.showMessageDialog(null,
                " Save failed: "+e.getMessage(),
                " Save failed",
                 JOptionPane.ERROR_MESSAGE);
    }
}
项目:BatBat-Game    文件:HUD.java   
public HUD(Player p) {
    player = p;
    try {
        BufferedImage image = ImageIO.read(
            getClass().getResourceAsStream(
                "/HUD/Hud.gif"
            )
        );
        heart = image.getSubimage(0, 0, 13, 12);
        life = image.getSubimage(0, 12, 12, 11);
    }
    catch(Exception e) {
        e.printStackTrace();
    }
}
项目:MTG-Card-Recognizer    文件:ImageUtil.java   
public static BufferedImage getCardImage(String multiid){
    try{
        URL url = new URL("http://gatherer.wizards.com/Handlers/Image.ashx?multiverseid=" + multiid
                + "&type=card");
        return ImageIO.read(url);
    }catch(Exception e){
        return null;
    }
}
项目:Quavo    文件:ImageUtils.java   
public static BufferedImage verticalFlip(BufferedImage img) {
    int w = img.getWidth();
    int h = img.getHeight();
    BufferedImage flippedImage = new BufferedImage(w, h, img.getColorModel().getTransparency());
    Graphics2D g = flippedImage.createGraphics();
    g.drawImage(img, 0, 0, w, h, 0, h, w, 0, null);
    g.dispose();
    return flippedImage;
}
项目:OpenJSharp    文件:AquaImageFactory.java   
static BufferedImage getAppIconImageCompositedOn(final Image background, int scaleFactor) {

        final int scaledAlertIconSize = kAlertIconSize * scaleFactor;
        final int kAlertSubIconSize = (int) (scaledAlertIconSize * 0.5);
        final int kAlertSubIconInset = scaledAlertIconSize - kAlertSubIconSize;
        final Icon smallAppIconScaled = new AquaIcon.CachingScalingIcon(
                kAlertSubIconSize, kAlertSubIconSize) {
                    Image createImage() {
                        return getGenericJavaIcon();
                    }
                };

        final BufferedImage image = new BufferedImage(scaledAlertIconSize,
                scaledAlertIconSize, BufferedImage.TYPE_INT_ARGB_PRE);
        final Graphics g = image.getGraphics();
        g.drawImage(background, 0, 0,
                scaledAlertIconSize, scaledAlertIconSize, null);
        if (g instanceof Graphics2D) {
            // improves icon rendering quality in Quartz
            ((Graphics2D) g).setRenderingHint(RenderingHints.KEY_RENDERING,
                    RenderingHints.VALUE_RENDER_QUALITY);
        }

        smallAppIconScaled.paintIcon(null, g,
                kAlertSubIconInset, kAlertSubIconInset);
        g.dispose();

        return image;
    }
项目:openjdk-jdk10    文件:bug6302464.java   
private static HashSet getAntialiasedColors(Object aaHint, int lcdContrast) {

        JLabel label = new JLabel("ABCD");
        label.setSize(label.getPreferredSize());
        label.putClientProperty(KEY_TEXT_ANTIALIASING, aaHint);
        label.putClientProperty(KEY_TEXT_LCD_CONTRAST, lcdContrast);

        int w = label.getWidth();
        int h = label.getHeight();

        BufferedImage buffImage = new BufferedImage(w, h, BufferedImage.TYPE_INT_RGB);
        Graphics2D g = buffImage.createGraphics();
        g.setColor(Color.WHITE);
        g.fillRect(0, 0, w, h);
        label.paint(g);
        g.dispose();

        HashSet<Color> colors = new HashSet<>();

        for (int i = 0; i < w; i++) {
            for (int j = 0; j < h; j++) {
                Color color = new Color(buffImage.getRGB(i, j));
                colors.add(color);
            }
        }

        return colors;
    }
项目:openjdk-jdk10    文件:MultiResolutionDisabledImageTest.java   
private static BufferedImage createImage(int scale) throws Exception {
    BufferedImage image = new BufferedImage(scale * 200, scale * 300,
                                            BufferedImage.TYPE_INT_RGB);
    Graphics g = image.createGraphics();
    g.setColor(scale == 1 ? COLOR_1X : COLOR_2X);
    g.fillRect(0, 0, scale * 200, scale * 300);
    g.dispose();
    return image;
}
项目:pds    文件:SysLoginController.java   
@RequestMapping("captcha.jpg")
public void captcha(HttpServletResponse response)throws ServletException, IOException {
       response.setHeader("Cache-Control", "no-store, no-cache");
       response.setContentType("image/jpeg");

       //生成文字验证码
       String text = producer.createText();
       //生成图片验证码
       BufferedImage image = producer.createImage(text);
       //保存到shiro session
       ShiroUtils.setSessionAttribute(Constants.KAPTCHA_SESSION_KEY, text);

       ServletOutputStream out = response.getOutputStream();
       ImageIO.write(image, "jpg", out);
}