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


Java BufferedImage类代码示例

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


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

示例1: getUnitImage

import java.awt.image.BufferedImage; //导入依赖的package包/类
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;
}
 
开发者ID:FreeCol,项目名称:freecol,代码行数:20,代码来源:ImageLibrary.java

示例2: getAntialiasedColors

import java.awt.image.BufferedImage; //导入依赖的package包/类
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;
    }
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:29,代码来源:bug6302464.java

示例3: checkBI

import java.awt.image.BufferedImage; //导入依赖的package包/类
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));
            }
        }
    }
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:26,代码来源:OnScreenRenderingResizeTest.java

示例4: createDataBP

import java.awt.image.BufferedImage; //导入依赖的package包/类
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;
}
 
开发者ID:lambdalab-mirror,项目名称:jdk8u-jdk,代码行数:21,代码来源:BufImgSurfaceData.java

示例5: loadImage

import java.awt.image.BufferedImage; //导入依赖的package包/类
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);
    
}
 
开发者ID:jfcameron,项目名称:G2Dj,代码行数:27,代码来源:Resources.java

示例6: GIFFrame

import java.awt.image.BufferedImage; //导入依赖的package包/类
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;
}
 
开发者ID:fatmanspanda,项目名称:SpriteAnimator,代码行数:23,代码来源:AnimatedGIFWriter.java

示例7: saveCompress

import java.awt.image.BufferedImage; //导入依赖的package包/类
/**
 * @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;
    }
}
 
开发者ID:tong12580,项目名称:OutsourcedProject,代码行数:25,代码来源:ImageUtil.java

示例8: testDisabledStateOfJMenu

import java.awt.image.BufferedImage; //导入依赖的package包/类
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.");
            }
        }

    }
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:19,代码来源:JMenuItemsTest.java

示例9: testDrawWithNullInfo

import java.awt.image.BufferedImage; //导入依赖的package包/类
/**
 * 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);
}
 
开发者ID:parabuild-ci,项目名称:parabuild-ci,代码行数:19,代码来源:BarChart3DTests.java

示例10: compressAndSave

import java.awt.image.BufferedImage; //导入依赖的package包/类
/**
 *
 * @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;
    }
}
 
开发者ID:tong12580,项目名称:OutsourcedProject,代码行数:26,代码来源:ImageUtil.java

示例11: Transform

import java.awt.image.BufferedImage; //导入依赖的package包/类
@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);
    }
}
 
开发者ID:lambdalab-mirror,项目名称:jdk8u-jdk,代码行数:25,代码来源:D3DBlitLoops.java

示例12: saveImage

import java.awt.image.BufferedImage; //导入依赖的package包/类
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();
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:21,代码来源:ImageWriterCompressionTest.java

示例13: processFontData

import java.awt.image.BufferedImage; //导入依赖的package包/类
/**
 * 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;
}
 
开发者ID:Valkryst,项目名称:VTerminal,代码行数:37,代码来源:FontLoader.java

示例14: processThumbnailUpdate

import java.awt.image.BufferedImage; //导入依赖的package包/类
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);
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:18,代码来源:UserPluginMetadataFormatTest.java

示例15: main

import java.awt.image.BufferedImage; //导入依赖的package包/类
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");
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:20,代码来源:EncodeSubImageTest.java


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