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


Java Image.getHeight方法代码示例

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


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

示例1: toBufferedImage

import java.awt.Image; //导入方法依赖的package包/类
/**
 * Converts a given Image into a BufferedImage.
 *
 * @param img The Image to be converted
 * @return The converted BufferedImage
 */
private static BufferedImage toBufferedImage(final Image img) {
    BufferedImage bimage = new BufferedImage(img.getWidth(null),
            img.getHeight(null), BufferedImage.TYPE_INT_RGB);

    // Draw the image on to the buffered image
    Graphics2D g2 = bimage.createGraphics();
    boolean x = false;
    while (!x) {
        x = g2.drawImage(img, 0, 0, null);
    }
    g2.dispose();

    // Return the buffered image
    return bimage;
}
 
开发者ID:adobe,项目名称:stock-api-sdk,代码行数:22,代码来源:ApiUtils.java

示例2: scaleImageByHeight

import java.awt.Image; //导入方法依赖的package包/类
/**
 * 灏嗗浘鐗囦互height涓哄噯杩涜绛夋瘮缂╂斁銆�
 * 
 * @param imageBytes
 * @param height
 * @param imageFormatName
 * @return
 */
public static byte[] scaleImageByHeight(byte[] imageBytes, int height,
		String imageFormatName) {
	Image img = null;
	int width = 0;
	try {
		img = ImageIO.read(new ByteArrayInputStream(imageBytes));
		int old_w = img.getWidth(null);
		int old_h = img.getHeight(null);
		if (old_h > 0 && old_w > 0) {
			// 浠ラ珮搴︿负鍑嗭紝璁$畻瀹藉害 绛夋瘮缂╂斁
			width = (int) ((float) height / old_h * old_w);
		}
	} catch (Exception e) {
		logger.error("scaleImageByHeight faild!", e);
	}
	return ImageUtils.scaleImage(imageBytes, width, height,
			Image.SCALE_SMOOTH, imageFormatName);
}
 
开发者ID:marlonwang,项目名称:raven,代码行数:27,代码来源:ImageUtils.java

示例3: waitForDimensions

import java.awt.Image; //导入方法依赖的package包/类
synchronized private void waitForDimensions(Image img) {
    mHeight = img.getHeight(this);
    mWidth = img.getWidth(this);
    while (!badImage && (mWidth < 0 || mHeight < 0)) {
        try {
            Thread.sleep(50);
        } catch(InterruptedException e) {
            // do nothing.
        }
        mHeight = img.getHeight(this);
        mWidth = img.getWidth(this);
    }
    if (badImage) {
        mHeight = 0;
        mWidth = 0;
    }
}
 
开发者ID:SunburstApps,项目名称:OpenJSharp,代码行数:18,代码来源:PeekGraphics.java

示例4: testToolkitMultiResolutionImageLoad

import java.awt.Image; //导入方法依赖的package包/类
static void testToolkitMultiResolutionImageLoad(Image image)
    throws Exception {

    MediaTracker tracker = new MediaTracker(new JPanel());
    tracker.addImage(image, 0);
    tracker.waitForID(0);
    if (tracker.isErrorAny()) {
        throw new RuntimeException("Error during image loading");
    }
    tracker.removeImage(image, 0);

    testImageLoaded(image);

    int w = image.getWidth(null);
    int h = image.getHeight(null);

    Image resolutionVariant = ((MultiResolutionImage) image)
        .getResolutionVariant(2 * w, 2 * h);

    if (image == resolutionVariant) {
        throw new RuntimeException("Resolution variant is not loaded");
    }

    testImageLoaded(resolutionVariant);
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:26,代码来源:MultiResolutionImageTest.java

示例5: picture

import java.awt.Image; //导入方法依赖的package包/类
/**
 * Draws the specified image centered at (<em>x</em>, <em>y</em>),
 * rotated given number of degrees.
 * The supported image formats are JPEG, PNG, and GIF.
 *
 * @param  x the center <em>x</em>-coordinate of the image
 * @param  y the center <em>y</em>-coordinate of the image
 * @param  filename the name of the image/picture, e.g., "ball.gif"
 * @param  degrees is the number of degrees to rotate counterclockwise
 * @throws IllegalArgumentException if the image filename is invalid
 */
public static void picture(double x, double y, String filename, double degrees) {
    // BufferedImage image = getImage(filename);
    Image image = getImage(filename);
    double xs = scaleX(x);
    double ys = scaleY(y);
    // int ws = image.getWidth();    // can call only if image is a BufferedImage
    // int hs = image.getHeight();
    int ws = image.getWidth(null);
    int hs = image.getHeight(null);
    if (ws < 0 || hs < 0) throw new IllegalArgumentException("image " + filename + " is corrupt");

    offscreen.rotate(Math.toRadians(-degrees), xs, ys);
    offscreen.drawImage(image, (int) Math.round(xs - ws/2.0), (int) Math.round(ys - hs/2.0), null);
    offscreen.rotate(Math.toRadians(+degrees), xs, ys);

    draw();
}
 
开发者ID:DCMMC,项目名称:Java-Algorithms-Learning,代码行数:29,代码来源:StdDraw.java

示例6: toBufferedImage

import java.awt.Image; //导入方法依赖的package包/类
private BufferedImage toBufferedImage(Image image) {
    if (image instanceof BufferedImage) {
        return (BufferedImage) image;
    }
    BufferedImage buffer = new BufferedImage(image.getWidth(null), image.getHeight(null), 2);
    Graphics2D g = buffer.createGraphics();
    g.drawImage(image, null, null);
    image.flush();
    return buffer;
}
 
开发者ID:me4502,项目名称:AdvancedServerListIcons,代码行数:11,代码来源:ImageHandler.java

示例7: _getImageSize

import java.awt.Image; //导入方法依赖的package包/类
private Dimension _getImageSize(
  PaintContext context,
  Image        image
  )
{
  if (image == null)
    return new Dimension(0,0);

  ImageObserver observer = context.getImageObserver();

  return new Dimension(image.getWidth(observer),
                       image.getHeight(observer));
}
 
开发者ID:apache,项目名称:myfaces-trinidad,代码行数:14,代码来源:CompositeButtonPainter.java

示例8: createMirroredImage

import java.awt.Image; //导入方法依赖的package包/类
public static BufferedImage createMirroredImage(Image image) {
    if(image == null)
        return null;
    final int width = image.getWidth(null);
    final int height = image.getHeight(null);
    BufferedImage result = new BufferedImage(width, height,
        BufferedImage.TYPE_INT_ARGB);
    Graphics2D g = result.createGraphics();
    g.drawImage(image, width, 0, -width, height, null);
    g.dispose();
    return result;
}
 
开发者ID:wintertime,项目名称:FreeCol,代码行数:13,代码来源:ImageLibrary.java

示例9: transform

import java.awt.Image; //导入方法依赖的package包/类
public void transform(String originalFile, String thumbnailFile, int thumbWidth, int thumbHeight, int quality) throws Exception 
{
	Image image = javax.imageio.ImageIO.read(new File(originalFile));
    
    double thumbRatio = (double)thumbWidth / (double)thumbHeight;
    int imageWidth    = image.getWidth(null);
    int imageHeight   = image.getHeight(null);
    double imageRatio = (double)imageWidth / (double)imageHeight;
    if (thumbRatio < imageRatio) 
    {
    	thumbHeight = (int)(thumbWidth / imageRatio);
    } 
    else 
    {
      	thumbWidth = (int)(thumbHeight * imageRatio);
    }
    
	if(imageWidth < thumbWidth && imageHeight < thumbHeight)
	{
		thumbWidth = imageWidth;
		thumbHeight = imageHeight;
	}
	else if(imageWidth < thumbWidth)
		thumbWidth = imageWidth;
	else if(imageHeight < thumbHeight)
		thumbHeight = imageHeight;

    BufferedImage thumbImage = new BufferedImage(thumbWidth, thumbHeight, BufferedImage.TYPE_INT_RGB);
    Graphics2D graphics2D = thumbImage.createGraphics();
    graphics2D.setBackground(Color.WHITE);
   	graphics2D.setPaint(Color.WHITE); 
   	graphics2D.fillRect(0, 0, thumbWidth, thumbHeight);
    graphics2D.setRenderingHint(RenderingHints.KEY_INTERPOLATION, RenderingHints.VALUE_INTERPOLATION_BILINEAR);
    graphics2D.drawImage(image, 0, 0, thumbWidth, thumbHeight, null);
    
	javax.imageio.ImageIO.write(thumbImage, "JPG", new File(thumbnailFile));
}
 
开发者ID:LuJiangLin,项目名称:TestDemo1-github,代码行数:38,代码来源:ThumbnailGenerator.java

示例10: makeTransparent

import java.awt.Image; //导入方法依赖的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

示例11: getBigSystemIcon

import java.awt.Image; //导入方法依赖的package包/类
public static ImageIcon getBigSystemIcon(Image image) throws Exception {
	if (image.getWidth(null) < 20 || image.getHeight(null) < 20) {
		if (image.getWidth(null) > image.getHeight(null)) {
			width = 24;
			height = image.getHeight(null) * 24 / image.getWidth(null);
		} else {
			height = 24;
			width = image.getWidth(null) * 24 / image.getHeight(null);
		}
	} else {
		return new ImageIcon(image);
	}

	dest = new BufferedImage(width, height, BufferedImage.TYPE_3BYTE_BGR);
	dest2 = new BufferedImage(width, height, BufferedImage.TYPE_3BYTE_BGR);

	g = dest.getGraphics();
	g.setColor(Color.white);
	g.fillRect(0, 0, 22, 22);
	g.drawImage(image, 0, 0, width, height, null);

	g.dispose();

	sharpenOperator.filter(dest, dest2);

	return new ImageIcon(dest);
}
 
开发者ID:transwarpio,项目名称:rapidminer,代码行数:28,代码来源:Tools.java

示例12: toBufferedImage

import java.awt.Image; //导入方法依赖的package包/类
private static BufferedImage toBufferedImage(Image img){
    if (img instanceof BufferedImage){
        return (BufferedImage) img;
    }

    BufferedImage bimage = new BufferedImage(img.getWidth(null), img.getHeight(null), BufferedImage.SCALE_SMOOTH);

    Graphics2D bGr = bimage.createGraphics();
    bGr.drawImage(img, 0, 0, null);
    bGr.dispose();

    return bimage;
}
 
开发者ID:Obsidiam,项目名称:ameliaclient,代码行数:14,代码来源:ConnectorThread.java

示例13: createBufferedImage

import java.awt.Image; //导入方法依赖的package包/类
/**
 * Creates a buffered image out of a given {@code Image} object.
 * 
 * @param image The {@code Image} object.
 * @return The created {@code BufferedImage} object.
 */
public static BufferedImage createBufferedImage(Image image) {
    if(image == null)
        return null;
    BufferedImage result = new BufferedImage(image.getWidth(null),
        image.getHeight(null), BufferedImage.TYPE_INT_ARGB);
    Graphics2D g = result.createGraphics();
    g.drawImage(image, 0, 0, null);
    g.dispose();
    return result;
}
 
开发者ID:wintertime,项目名称:FreeCol,代码行数:17,代码来源:ImageLibrary.java

示例14: cutImage

import java.awt.Image; //导入方法依赖的package包/类
private static SpriteSheet cutImage(GraphicsConfiguration gc, String imageName, int xSize, int ySize) throws IOException 
{
	xSize*=GlobalOptions.resolution_factor;
	ySize*=GlobalOptions.resolution_factor;
			
	Image source = getImage(gc, imageName);		
			
	Image[][] cutsource = new Image[source.getWidth(null) / xSize][source.getHeight(null) / ySize];		
	
	for (int x = 0; x < source.getWidth(null) / xSize; x++) 
	{
		for (int y = 0; y < source.getHeight(null) / ySize; y++) 
		{
			Image image = gc.createCompatibleImage(xSize, ySize, Transparency.TRANSLUCENT);
			Graphics2D g = (Graphics2D) image.getGraphics();
							
			//g.setComposite(AlphaComposite.Src);
			
			//ENABLE PARTIAL TRANSPARENCY
			AlphaComposite ac = java.awt.AlphaComposite.getInstance(AlphaComposite.SRC);
	        g.setComposite(ac);						
			
			g.drawImage(source, -x * xSize, -y * ySize, null);
			g.dispose();
			
			cutsource[x][y] = image;
		}
	}		
	
	System.out.println(imageName);
	SpriteSheet ret = new SpriteSheet(xSize, ySize, source.getWidth(null) / xSize, source.getHeight(null) / ySize, cutsource);
	
	return ret;
}
 
开发者ID:CognitiveModeling,项目名称:BrainControl,代码行数:35,代码来源:Art.java

示例15: drawHiDPIImage

import java.awt.Image; //导入方法依赖的package包/类
private boolean drawHiDPIImage(Image img, int dx1, int dy1, int dx2,
                               int dy2, int sx1, int sy1, int sx2, int sy2,
                               Color bgcolor, ImageObserver observer) {

    if (SurfaceManager.getImageScale(img) != 1) {  // Volatile Image
        final int scale = SurfaceManager.getImageScale(img);
        sx1 = Region.clipScale(sx1, scale);
        sx2 = Region.clipScale(sx2, scale);
        sy1 = Region.clipScale(sy1, scale);
        sy2 = Region.clipScale(sy2, scale);
    } else if (img instanceof MultiResolutionImage) {
        // get scaled destination image size

        int width = img.getWidth(observer);
        int height = img.getHeight(observer);

        Image resolutionVariant = getResolutionVariant(
                (MultiResolutionImage) img, width, height,
                dx1, dy1, dx2, dy2, sx1, sy1, sx2, sy2);

        if (resolutionVariant != img && resolutionVariant != null) {
            // recalculate source region for the resolution variant

            ImageObserver rvObserver = MultiResolutionToolkitImage.
                    getResolutionVariantObserver(img, observer,
                            width, height, -1, -1);

            int rvWidth = resolutionVariant.getWidth(rvObserver);
            int rvHeight = resolutionVariant.getHeight(rvObserver);

            if (0 < width && 0 < height && 0 < rvWidth && 0 < rvHeight) {

                float widthScale = ((float) rvWidth) / width;
                float heightScale = ((float) rvHeight) / height;

                sx1 = Region.clipScale(sx1, widthScale);
                sy1 = Region.clipScale(sy1, heightScale);
                sx2 = Region.clipScale(sx2, widthScale);
                sy2 = Region.clipScale(sy2, heightScale);

                observer = rvObserver;
                img = resolutionVariant;
            }
        }
    }

    try {
        return imagepipe.scaleImage(this, img, dx1, dy1, dx2, dy2, sx1, sy1,
                                    sx2, sy2, bgcolor, observer);
    } catch (InvalidPipeException e) {
        try {
            revalidateAll();
            return imagepipe.scaleImage(this, img, dx1, dy1, dx2, dy2, sx1,
                                        sy1, sx2, sy2, bgcolor, observer);
        } catch (InvalidPipeException e2) {
            // Still catching the exception; we are not yet ready to
            // validate the surfaceData correctly.  Fail for now and
            // try again next time around.
            return false;
        }
    } finally {
        surfaceData.markDirty();
    }
}
 
开发者ID:SunburstApps,项目名称:OpenJSharp,代码行数:65,代码来源:SunGraphics2D.java


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