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


Java BufferedImage.getType方法代码示例

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


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

示例1: apply

import java.awt.image.BufferedImage; //导入方法依赖的package包/类
@Override
protected BufferedImage apply(BufferedImage img) {
	
	BufferedImage img2 = new BufferedImage(img.getWidth(), img.getHeight(), img.getType());
	Graphics2D g = img2.createGraphics();
	
	for(int y = 0; y < img.getHeight(); y++) {
		BufferedImage row = img.getSubimage(0, y, img.getWidth(), 1);
		
		int offset = Math.round((y/2f - img.getHeight()/4f) * (2 * shift * img.getWidth()));
		offset = offset % img.getWidth();
		
		g.drawImage(row, offset, y, null);
		g.drawImage(row, (offset < 0 ? 1 : -1) * img.getWidth() + offset, y, null);
	}

	g.dispose();
	
	return img2;
}
 
开发者ID:CalebKussmaul,项目名称:GIFKR,代码行数:21,代码来源:PerspectiveFilter.java

示例2: resizeImage

import java.awt.image.BufferedImage; //导入方法依赖的package包/类
/**
 *	Takes an Buffered Image and resizes it to TILE_SIZE x TILE_SIZE 
 */
private static BufferedImage resizeImage(BufferedImage sample, double sampleMinLat, double sampleMaxLat, double tileMinLat, double tileMaxLat) {
	BufferedImage img = new BufferedImage(TILE_SIZE, TILE_SIZE, sample.getType());
	double tileScale = TILE_SIZE / (tileMinLat - tileMaxLat);

	// s for source; d for destination; all measurements in pixels
	int sx1 = 0;
	int sy1 = 0;
	int sx2 = sample.getWidth();
	int sy2 = sample.getHeight();

	int dx1 = 0;
	int dy1 = (int) ((sampleMaxLat - tileMaxLat) * tileScale);
	int dx2 = TILE_SIZE;
	int dy2 = (int) ((sampleMinLat - tileMaxLat) * tileScale);

	img.createGraphics().drawImage(sample, dx1, dy1, dx2, dy2, sx1, sy1, sx2, sy2, null);

	return img;
}
 
开发者ID:iedadata,项目名称:geomapapp,代码行数:23,代码来源:GridTileLayer.java

示例3: rotate180

import java.awt.image.BufferedImage; //导入方法依赖的package包/类
public static BufferedImage rotate180(BufferedImage inputImage) {
	// The most of code is same as before
	int width = inputImage.getWidth();
	int height = inputImage.getHeight();
	BufferedImage returnImage = new BufferedImage(height, width, inputImage.getType());
	// We have to change the width and height because when you rotate the
	// image by 90 degree, the
	// width is height and height is width <img
	// src='http://forum.codecall.net/public/style_emoticons/<#EMO_DIR#>/smile.png'
	// class='bbc_emoticon' alt=':)' />

	for (int x = 0; x < width; x++) {
		for (int y = 0; y < height; y++) {
			int nX = height - x - 1;
			int nY = height - (width - y - 1) - 1;
			returnImage.setRGB(nX, nY, inputImage.getRGB(x, y));
		}
	}
	return returnImage;
}
 
开发者ID:WElRD,项目名称:StreamDeckCore,代码行数:21,代码来源:IconHelper.java

示例4: setPixels

import java.awt.image.BufferedImage; //导入方法依赖的package包/类
/**
 * <p>Writes a rectangular area of pixels in the destination
 * <code>BufferedImage</code>. Calling this method on
 * an image of type different from <code>BufferedImage.TYPE_INT_ARGB</code>
 * and <code>BufferedImage.TYPE_INT_RGB</code> will unmanage the image.</p>
 *
 * @param img the destination image
 * @param x the x location at which to start storing pixels
 * @param y the y location at which to start storing pixels
 * @param w the width of the rectangle of pixels to store
 * @param h the height of the rectangle of pixels to store
 * @param pixels an array of pixels, stored as integers
 * @throws IllegalArgumentException is <code>pixels</code> is non-null and
 *   of length &lt; w*h
 */
public static void setPixels(BufferedImage img,
                             int x, int y, int w, int h, int[] pixels) {
    if (pixels == null || w == 0 || h == 0) {
        return;
    } else if (pixels.length < w * h) {
        throw new IllegalArgumentException("pixels array must have a length" +
                                           " >= w*h");
    }

    int imageType = img.getType();
    if (imageType == BufferedImage.TYPE_INT_ARGB ||
        imageType == BufferedImage.TYPE_INT_RGB) {
        WritableRaster raster = img.getRaster();
        raster.setDataElements(x, y, w, h, pixels);
    } else {
        // Unmanages the image
        img.setRGB(x, y, w, h, pixels, 0, w);
    }
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:35,代码来源:EffectUtils.java

示例5: resizeSource

import java.awt.image.BufferedImage; //导入方法依赖的package包/类
private static BufferedImage resizeSource(BufferedImage image) {
    double factor = 720d / image.getWidth();
    int scaledHeight = (int) (image.getHeight() * factor);
    int scaledWidth = (int) (image.getWidth() * factor);

    Image tmp = image.getScaledInstance(scaledWidth, scaledHeight, Image.SCALE_SMOOTH);
    int type = image.getType();
    if (type == 0)
        type = 5; // hacky but does work

    BufferedImage dimg = new BufferedImage(scaledWidth, scaledHeight, type);
    Graphics2D g2d = dimg.createGraphics();
    g2d.drawImage(tmp, 0, 0, null);
    g2d.dispose();
    return dimg;
}
 
开发者ID:BlackCraze,项目名称:GameResourceBot,代码行数:17,代码来源:Preprocessor.java

示例6: resizeImage

import java.awt.image.BufferedImage; //导入方法依赖的package包/类
private static byte[] resizeImage(byte[] imageInByte) throws IOException {
    InputStream in = new ByteArrayInputStream(imageInByte);
    BufferedImage originalImage = ImageIO.read(in);

    final int imageWidth = 60;
    final int imageHeight = imageWidth * originalImage.getHeight() / originalImage.getWidth();

    BufferedImage resizedImage = new BufferedImage(imageWidth, imageHeight, originalImage.getType());
    Graphics2D g = resizedImage.createGraphics();
    g.drawImage(originalImage, 0, 0, imageWidth, imageHeight, null);
    g.dispose();

    byte[] imageInByteOut = null;
    try (ByteArrayOutputStream out = new ByteArrayOutputStream()) {
        ImageIO.write(resizedImage, "png", out);
        out.flush();
        imageInByteOut = out.toByteArray();
    }

    return imageInByteOut;
}
 
开发者ID:Microsoft,项目名称:movie-db-java-on-azure,代码行数:22,代码来源:Function.java

示例7: doTest

import java.awt.image.BufferedImage; //导入方法依赖的package包/类
public void doTest(int type) {
    System.out.println("Test for type " + describeType(type));

    BufferedImage src = createTestImage(type);

    BufferedImage res = null;

    System.out.println("Testing null destination...");
    try {
        res = op.filter(src, null);
    } catch (ImagingOpException e) {
        throw new RuntimeException("Test FAILED!", e);
    }

    if (res == null ||
        ((src.getType() != BufferedImage.TYPE_BYTE_INDEXED) &&
         (res.getType() != src.getType())))
    {
        throw new RuntimeException("Test FAILED!");
    }
    System.out.println("Test PASSED.");
}
 
开发者ID:lambdalab-mirror,项目名称:jdk8u-jdk,代码行数:23,代码来源:OpCompatibleImageTest.java

示例8: 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

示例9: resampleImage

import java.awt.image.BufferedImage; //导入方法依赖的package包/类
public BufferedImage resampleImage(BufferedImage sample, double sampleMinLat, double sampleMaxLat, double tileMinLat, double tileMaxLat, int tileSize) {
 			BufferedImage img = new BufferedImage(sample.getWidth(), tileSize, sample.getType());
			double tileScale_DegreesPerPixel = (tileMinLat - tileMaxLat) / tileSize;

			// Y = 0 is equator
			double sampleMinY = Math.log( Math.tan(Math.toRadians(sampleMinLat)) + 
									1 / Math.cos(Math.toRadians(sampleMinLat)) );
			double sampleMaxY = Math.log( Math.tan(Math.toRadians(sampleMaxLat)) + 
									1 / Math.cos(Math.toRadians(sampleMaxLat)) );
			
			double sampleYDelta = sampleMinY - sampleMaxY;

			int rgb[] = new int[img.getWidth()];
			for (int tileRow = 0; tileRow < tileSize; tileRow++) {
				double lat = tileScale_DegreesPerPixel * tileRow + tileMaxLat;
				
				if (lat > 81) continue;
				if (lat < -79) continue;
				
				lat = Math.toRadians(lat);
				
				double sampleY = (Math.log(Math.tan(lat) + 1 / Math.cos(lat)));
				
				double sampleRatio = (sampleY - sampleMaxY) / sampleYDelta;
//				System.out.println(Math.toDegrees(lat) + "\t" + sampleY + "\t" + sampleRatio);
				
				if (sampleRatio > 1 || sampleRatio < 0) {
					System.out.println("Outside sample range");
					continue;
				}
				
				int sampleRow = (int) Math.floor(sampleRatio * sample.getHeight());
				rgb = sample.getRGB(0, sampleRow, sample.getWidth(), 1, rgb, 0, 1);
				img.setRGB(0, tileRow, img.getWidth(), 1, rgb, 0, 1);
			}
			
			return img; 
		}
 
开发者ID:iedadata,项目名称:geomapapp,代码行数:39,代码来源:ImageResampler.java

示例10: 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:HOMlab,项目名称:QN-ACTR-Release,代码行数:11,代码来源:EnlargePDF.java

示例11: copyImage

import java.awt.image.BufferedImage; //导入方法依赖的package包/类
private BufferedImage copyImage(BufferedImage i)
 {
 	BufferedImage img = new BufferedImage(i.getWidth(), i.getHeight(), i.getType());
	for (int y = 0; y < i.getHeight(); y++)
	{
		for (int x = 0; x < i.getWidth(); x++)
		{
			int rgb = i.getRGB(x, y);
			img.setRGB(x, y, rgb);
		}
	}
return img;
 }
 
开发者ID:DerekBabb,项目名称:CyberSecurity,代码行数:14,代码来源:PictureEdit.java

示例12: resizeImage

import java.awt.image.BufferedImage; //导入方法依赖的package包/类
static BufferedImage resizeImage(BufferedImage originalImage) {
    int imageType = originalImage.getType();
    if (imageType == 0) imageType = 5;

    BufferedImage resizedImage = new BufferedImage(IMG_WIDTH, IMG_HEIGHT, imageType);

    Graphics2D g = resizedImage.createGraphics();
    g.drawImage(originalImage, 0, 0, IMG_WIDTH, IMG_HEIGHT, null);
    g.dispose();

    return resizedImage;
}
 
开发者ID:kevalpatel2106,项目名称:EmoticonGIFKeyboard,代码行数:13,代码来源:Utils.java

示例13: scaleImage

import java.awt.image.BufferedImage; //导入方法依赖的package包/类
/**
 * Resizes an image using a Graphics2D object backed by a BufferedImage.
 *
 * @param srcImg - Source image to scale
 * @param width - Desired width
 * @param height - Desired height
 * @return - The new resized image
 */
public static BufferedImage scaleImage(BufferedImage srcImg, int width, int height) {
    BufferedImage resizedImg = new BufferedImage(width, height, srcImg.getType());
    Graphics2D g2 = resizedImg.createGraphics();
    g2.setRenderingHint(RenderingHints.KEY_INTERPOLATION, RenderingHints.VALUE_INTERPOLATION_NEAREST_NEIGHBOR);
    g2.drawImage(srcImg, 0, 0, width, height, null);
    g2.dispose();

    return resizedImg;
}
 
开发者ID:mcdcorp,项目名称:opentest,代码行数:18,代码来源:ImageUtil.java

示例14: prepareMainPreview

import java.awt.image.BufferedImage; //导入方法依赖的package包/类
/**
 * Prepares the main preview window image prior to rendering (puts the preprocessed image left, processed
 * image right, does any scaling necessary to fit the screen)
 *
 * @param preprocessed the preprocessed image
 * @param result the result image
 * @param  fpsString the current processing frame rate
 * @return the image ready to render in the main window
 */
public static BufferedImage prepareMainPreview(BufferedImage preprocessed, BufferedImage result, float fpsString) {
	BufferedImage left = preprocessed;
	BufferedImage right = result;
	int width = result.getWidth();
	int height = result.getHeight();
	boolean needsScaling = false;
	while (imageOutOfScreenBounds(width*2, height)) {
		width /=2;
		height /=2;
		needsScaling = true;
	}
	if (needsScaling) {
		left = ImageHelper.quickScaleImage(preprocessed, width, height);
		right = ImageHelper.smoothScaleImage(result, width, height); // Smooth scale needed in order to maintain dither patterns in preview
	}
	BufferedImage mainPreviewImage = new BufferedImage(width*2, height, result.getType());
	Graphics preBuffer = mainPreviewImage.createGraphics();
	preBuffer.drawImage(left, 0, 0, null);
	preBuffer.drawImage(right, width, 0, null);
	if (OptionsObject.getInstance().getFpsCounter()) {
		preBuffer.setColor(Color.WHITE);
		preBuffer.drawString(getCaption("main_fps_overlay") + " " + fpsString, 10, 20);
	}
	preBuffer.dispose();
	return mainPreviewImage;
}
 
开发者ID:KodeMunkie,项目名称:imagetozxspec,代码行数:36,代码来源:ImageHelper.java

示例15: fillBackground

import java.awt.image.BufferedImage; //导入方法依赖的package包/类
public static BufferedImage fillBackground(BufferedImage img, Color color) {
	BufferedImage nImg = new BufferedImage(img.getWidth(), img.getHeight(), img.getType());
	Graphics2D g = nImg.createGraphics();
	g.setColor(color);
	g.fillRect(0, 0, nImg.getWidth(), nImg.getHeight());
	g.drawImage(img, 0, 0, null);
	g.dispose();
	return nImg;
}
 
开发者ID:WElRD,项目名称:StreamDeckCore,代码行数:10,代码来源:IconHelper.java


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