當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。