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


Java BufferedImage.getHeight方法代码示例

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


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

示例1: convertPngToJpeg

import java.awt.image.BufferedImage; //导入方法依赖的package包/类
private String convertPngToJpeg(String pngBase64) throws IOException {
	byte[] pngBinary = DatatypeConverter.parseBase64Binary(pngBase64);
	InputStream in = new ByteArrayInputStream(pngBinary);
	BufferedImage pngImage = ImageIO.read(in);

	int width = pngImage.getWidth(), height = pngImage.getHeight();
	BufferedImage jpgImage = new BufferedImage(width, height, BufferedImage.TYPE_INT_RGB);

	Graphics2D g = jpgImage.createGraphics();
	g.setRenderingHint(RenderingHints.KEY_INTERPOLATION, RenderingHints.VALUE_INTERPOLATION_BICUBIC);
	g.setBackground(Color.WHITE);
	g.clearRect(0, 0, width, height);
	g.drawImage(pngImage, 0, 0, width, height, null);
	g.dispose();

	final ImageWriter writer = ImageIO.getImageWritersByFormatName("jpeg").next();
	ByteArrayOutputStream baos = new ByteArrayOutputStream();
	writer.setOutput(ImageIO.createImageOutputStream(baos));
	writer.write(null, new IIOImage(jpgImage, null, null), JPEG_PARAMS);

	String jpgBase64 = DatatypeConverter.printBase64Binary(baos.toByteArray());
	return jpgBase64;
}
 
开发者ID:JensN4,项目名称:png_to_jpg_in_svg,代码行数:24,代码来源:PNG_to_JPG_in_SVG.java

示例2: filter

import java.awt.image.BufferedImage; //导入方法依赖的package包/类
public BufferedImage filter(BufferedImage src, BufferedImage dst) {
    int width = src.getWidth();
    int height = src.getHeight();

    if (dst == null)
        dst = createCompatibleDestImage(src, null);

    int[] inPixels = new int[width * height];
    int[] outPixels = new int[width * height];
    getRGB(src, 0, 0, width, height, inPixels);

    blur(inPixels, outPixels, width, height, radius);
    blur(outPixels, inPixels, height, width, radius);

    setRGB(dst, 0, 0, width, height, inPixels);
    return dst;
}
 
开发者ID:GoldRenard,项目名称:JuniperBotJ,代码行数:18,代码来源:BoxBlurFilter.java

示例3: swapColor

import java.awt.image.BufferedImage; //导入方法依赖的package包/类
/**
 * Swaps two colors on an image.
 *
 * @param image
 *          The image.
 *
 * @param oldColor
 *          The color to swap out.
 *
 * @param newColor
 *          The color to swap in.
 *
 * @return
 *          The result image.
 *
 * @throws NullPointerException
 *           If the image or either color is null.
 */
default BufferedImage swapColor(final @NonNull BufferedImage image, final @NonNull Color oldColor, final @NonNull Color newColor) {
    final BufferedImage result = ImageCache.cloneImage(image);

    final int newRGB = newColor.getRGB();
    final int oldRGB = oldColor.getRGB();

    for (int y = 0; y < result.getHeight(); y++) {
        for (int x = 0; x < result.getWidth(); x++) {
            int pixel = result.getRGB(x, y);

            if (pixel == oldRGB) {
                result.setRGB(x, y, newRGB);
            }
        }
    }

    return result;
}
 
开发者ID:Valkryst,项目名称:VTerminal,代码行数:37,代码来源:Shader.java

示例4: enlargeImage

import java.awt.image.BufferedImage; //导入方法依赖的package包/类
/**
 * Increases image.
 *
 * @param image an image to enlarge.
 * @param zoom A scale.
 * @return a result image.
 */
public static BufferedImage enlargeImage(BufferedImage image, int zoom) {
    int wight = image.getWidth();
    int height = image.getHeight();
    BufferedImage result = new BufferedImage(wight * zoom,
            height * zoom,
            image.getType());
    int rgb;
    for (int x = 0; x < wight; x++) {
        for (int y = 0; y < height; y++) {
            rgb = image.getRGB(x, y);
            for (int i = 0; i < zoom; i++) {
                for (int j = 0; j < zoom; j++) {
                    result.setRGB(x * zoom + i,
                            y * zoom + j,
                            rgb);
                }
            }
        }
    }
    return result;
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:29,代码来源:ImageTool.java

示例5: fitHeight

import java.awt.image.BufferedImage; //导入方法依赖的package包/类
public static BufferedImage fitHeight(BufferedImage img, int width, int height, boolean fast){
	img=resize(img, (int)(img.getWidth()*(height/(double)img.getHeight())), height, fast);
	if(img.getHeight()>height){
		img=img.getSubimage((img.getWidth()-width)/2, 0, width, img.getHeight());
	}

	BufferedImage fullImage=new BufferedImage(width, height, BufferedImage.TYPE_INT_ARGB);
	Graphics2D g=(Graphics2D)fullImage.getGraphics();
	if(!fast){
		g.setRenderingHint(RenderingHints.KEY_RENDERING, RenderingHints.VALUE_RENDER_QUALITY);
	}
	g.drawImage(img, (width-img.getWidth())/2, 0, null);

	g.dispose();

	return fullImage;	
}
 
开发者ID:CalebKussmaul,项目名称:GIFKR,代码行数:18,代码来源:ImageTools.java

示例6: BufferedImageLuminanceSource

import java.awt.image.BufferedImage; //导入方法依赖的package包/类
public BufferedImageLuminanceSource(BufferedImage image, int left,
        int top, int width, int height) {
    super(width, height);

    int sourceWidth = image.getWidth();
    int sourceHeight = image.getHeight();
    if (left + width > sourceWidth || top + height > sourceHeight) {
        throw new IllegalArgumentException(
                "Crop rectangle does not fit within image data.");
    }

    for (int y = top; y < top + height; y++) {
        for (int x = left; x < left + width; x++) {
            if ((image.getRGB(x, y) & 0xFF000000) == 0) {
                image.setRGB(x, y, 0xFFFFFFFF); // = white
            }
        }
    }

    this.image = new BufferedImage(sourceWidth, sourceHeight,
            BufferedImage.TYPE_BYTE_GRAY);
    this.image.getGraphics().drawImage(image, 0, 0, null);
    this.left = left;
    this.top = top;
}
 
开发者ID:HuiJa,项目名称:bicycleSharingServer,代码行数:26,代码来源:BufferedImageLuminanceSource.java

示例7: getARGB

import java.awt.image.BufferedImage; //导入方法依赖的package包/类
public static int[][] getARGB( String path ){
    BufferedImage bi;
    try {
        bi = ImageIO.read( new File(path) );
    } catch (IOException ex) {
        Logger.getLogger(ImagesUtils.class.getName()).log(Level.SEVERE, null, ex);
        return null;
    }
    final int w = bi.getWidth();
    final int h = bi.getHeight();
    
    int[] argb = new int[w * h];
    bi.getRGB(0, 0, w, h, argb, 0, w);
   
    int[][] matrix = new int[w][h];
    int index = 0;
    for(int ih = 0; ih < h; ++ih){
        for(int iw = 0; iw < w; ++iw){
            matrix[iw][ih] = argb[index];
            
            ++index;
        }
    }
    
    return matrix;
}
 
开发者ID:asiermarzo,项目名称:Ultraino,代码行数:27,代码来源:ImagesUtils.java

示例8: readJMETexture

import java.awt.image.BufferedImage; //导入方法依赖的package包/类
@FXThread
private @NotNull Image readJMETexture(final int width, final int height, @NotNull final String externalForm,
                                      @NotNull final Path cacheFile) {

    final Editor editor = Editor.getInstance();
    final AssetManager assetManager = editor.getAssetManager();
    final Texture texture = assetManager.loadTexture(externalForm);

    final BufferedImage textureImage;
    try {
        textureImage = ImageToAwt.convert(texture.getImage(), false, true, 0);
    } catch (final UnsupportedOperationException e) {
        EditorUtil.handleException(LOGGER, this, e);
        return Icons.IMAGE_512;
    }

    final int imageWidth = textureImage.getWidth();
    final int imageHeight = textureImage.getHeight();

    return scaleAndWrite(width, height, cacheFile, textureImage, imageWidth, imageHeight);
}
 
开发者ID:JavaSaBr,项目名称:jmonkeybuilder,代码行数:22,代码来源:JavaFXImageManager.java

示例9: compare

import java.awt.image.BufferedImage; //导入方法依赖的package包/类
boolean compare(BufferedImage dst, BufferedImage gldImage, int x0, int y0,
                int dx, int dy)
{
    int width = gldImage.getWidth();
    int height = gldImage.getHeight();

    if (x0 < 0) x0 = 0;
    if (x0 > width - dx) x0 = width - dx;
    if (y0 < 0) y0 = 0;
    if (y0 > height - dy) y0 = height - dy;

    int c = 0;

    boolean result = true;
    for (int i = x0; i < x0 + dx; i++) {
        for (int j = y0; j < y0 + dy; j++) {
            boolean cmp = compare(dst.getRGB(i-x0,j-y0),
                                  gldImage.getRGB(i,j));
            result = cmp && result;
        }
    }
    return result;
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:24,代码来源:ImageComparator.java

示例10: createUnitLabel

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

示例11: write

import java.awt.image.BufferedImage; //导入方法依赖的package包/类
/**
 * Writes the data for this segment to the stream in
 * valid JPEG format.  The length written takes the thumbnail
 * width and height into account.  If necessary, the thumbnail
 * is clipped to 255 x 255 and a warning is sent to the writer
 * argument.  Progress updates are sent to the writer argument.
 */
void write(ImageOutputStream ios,
           BufferedImage thumb,
           JPEGImageWriter writer) throws IOException {
    int thumbWidth = 0;
    int thumbHeight = 0;
    int thumbLength = 0;
    int [] thumbData = null;
    if (thumb != null) {
        // Clip if necessary and get the data in thumbData
        thumbWidth = thumb.getWidth();
        thumbHeight = thumb.getHeight();
        if ((thumbWidth > MAX_THUMB_WIDTH)
            || (thumbHeight > MAX_THUMB_HEIGHT)) {
            writer.warningOccurred(JPEGImageWriter.WARNING_THUMB_CLIPPED);
        }
        thumbWidth = Math.min(thumbWidth, MAX_THUMB_WIDTH);
        thumbHeight = Math.min(thumbHeight, MAX_THUMB_HEIGHT);
        thumbData = thumb.getRaster().getPixels(0, 0,
                                                thumbWidth, thumbHeight,
                                                (int []) null);
        thumbLength = thumbData.length;
    }
    length = DATA_SIZE + LENGTH_SIZE + thumbLength;
    writeTag(ios);
    byte [] id = {0x4A, 0x46, 0x49, 0x46, 0x00};
    ios.write(id);
    ios.write(majorVersion);
    ios.write(minorVersion);
    ios.write(resUnits);
    write2bytes(ios, Xdensity);
    write2bytes(ios, Ydensity);
    ios.write(thumbWidth);
    ios.write(thumbHeight);
    if (thumbData != null) {
        writer.thumbnailStarted(0);
        writeThumbnailData(ios, thumbData, writer);
        writer.thumbnailComplete();
    }
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:47,代码来源:JFIFMarkerSegment.java

示例12: blur

import java.awt.image.BufferedImage; //导入方法依赖的package包/类
public static BufferedImage blur(BufferedImage srcImage) {
    int w = srcImage.getWidth();
    int h = srcImage.getHeight();

    int[] src = srcImage.getRGB(0, 0, w, h, null, 0, w);
    int[] dst = new int[src.length];

    System.out.println("Array size is " + src.length);
    System.out.println("Threshold is " + sThreshold);

    int processors = Runtime.getRuntime().availableProcessors();
    System.out.println(Integer.toString(processors) + " processor"
            + (processors != 1 ? "s are " : " is ")
            + "available");

    ForkBlur fb = new ForkBlur(src, 0, src.length, dst);

    ForkJoinPool pool = new ForkJoinPool();

    long startTime = System.currentTimeMillis();
    pool.invoke(fb);
    long endTime = System.currentTimeMillis();

    System.out.println("Image blur took " + (endTime - startTime) +
            " milliseconds.");

    BufferedImage dstImage =
            new BufferedImage(w, h, BufferedImage.TYPE_INT_ARGB);
    dstImage.setRGB(0, 0, w, h, dst, 0, w);

    return dstImage;
}
 
开发者ID:chaokunyang,项目名称:jkes,代码行数:33,代码来源:ForkBlur.java

示例13: convertToByteBuffer

import java.awt.image.BufferedImage; //导入方法依赖的package包/类
public static ByteBuffer convertToByteBuffer(BufferedImage image) {
	byte[] buffer = new byte[image.getWidth() * image.getHeight() * 4];
	int counter = 0;
	for (int i = 0; i < image.getHeight(); i++)
		for (int j = 0; j < image.getWidth(); j++) {
			int colorSpace = image.getRGB(j, i);
			buffer[counter + 0] = (byte) ((colorSpace << 8) >> 24);
			buffer[counter + 1] = (byte) ((colorSpace << 16) >> 24);
			buffer[counter + 2] = (byte) ((colorSpace << 24) >> 24);
			buffer[counter + 3] = (byte) (colorSpace >> 24);
			counter += 4;
		}
	return ByteBuffer.wrap(buffer);
}
 
开发者ID:TheThinMatrix,项目名称:LowPolyWater,代码行数:15,代码来源:IconLoader.java

示例14: convertType

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

示例15: optimizeForGraphicsHardware

import java.awt.image.BufferedImage; //导入方法依赖的package包/类
/**
 * Converts an image to an optimized version for the default screen.<br>
 * The optimized image should draw faster.
 * @param image The image to optimize.
 * @return Returns the optimized image.
 */
public static BufferedImage optimizeForGraphicsHardware(BufferedImage image) {
    try {
        // create an empty optimized BufferedImage
        GraphicsEnvironment ge = GraphicsEnvironment.getLocalGraphicsEnvironment();
        GraphicsDevice gd = ge.getDefaultScreenDevice();
        GraphicsConfiguration gc = gd.getDefaultConfiguration();
        int w = image.getWidth();
        int h = image.getHeight();

        // strange things happen on Linux and Windows on some systems when
        // monitors are set to 16 bit.
        boolean bit16 = gc.getColorModel().getPixelSize() < 24;
        final int transp;
        if (bit16) {
            transp = Transparency.TRANSLUCENT;
        } else {
            transp = image.getColorModel().getTransparency();
        }
        BufferedImage optimized = gc.createCompatibleImage(w, h, transp);

        // draw the passed image into the optimized image
        optimized.getGraphics().drawImage(image, 0, 0, null);
        return optimized;
    } catch (Exception e) {
        // return the original image if an exception occured.
        return image;
    }
}
 
开发者ID:berniejenny,项目名称:MapAnalyst,代码行数:35,代码来源:ImageUtils.java


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