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


Java BufferedImage.getSubimage方法代码示例

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


在下文中一共展示了BufferedImage.getSubimage方法的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: TopLeftPiece

import java.awt.image.BufferedImage; //导入方法依赖的package包/类
public TopLeftPiece(TileMap tm) {
	super(tm);
	try {	
		BufferedImage spritesheet = ImageIO.read(
			getClass().getResourceAsStream("/Sprites/Other/ballBatBoss.gif")
		);
		sprites = new BufferedImage[1];
		width = height = 4;
		sprites[0] = spritesheet.getSubimage(0, 0, 10, 10);
		animation.setFrames(sprites);
		animation.setDelay(-1);
	}
	catch(Exception e) {
		e.printStackTrace();
	}
}
 
开发者ID:tonikolaba,项目名称:BatBat-Game,代码行数:17,代码来源:TopLeftPiece.java

示例3: findImage

import java.awt.image.BufferedImage; //导入方法依赖的package包/类
@Override
public ImageFinderResult findImage(BufferedImage sourceImage, Rectangle sourceRect, BufferedImage templateImage, double desiredAccuracy) {
    BufferedImage subImage = sourceImage;
    if (sourceRect != null) {
        subImage = sourceImage.getSubimage(
                sourceRect.x,
                sourceRect.y,
                sourceRect.width,
                sourceRect.height);
    }

    Mat sourceMat = CvHelper.convertToMat(subImage);
    Mat templateMat = CvHelper.convertToMat(templateImage);

    return this.findImage(sourceMat, templateMat, desiredAccuracy);
}
 
开发者ID:mcdcorp,项目名称:opentest,代码行数:17,代码来源:ImageFinder.java

示例4: createContainer

import java.awt.image.BufferedImage; //导入方法依赖的package包/类
/**
 * @param params contains image resolution in int format in first two elements
 */
@Override
public Container createContainer(String[] params) throws IOException {
    BufferedImage image = getImage();
    if (params.length >= 2) {
        int w = Integer.parseInt(params[0]);
        int h = Integer.parseInt(params[1]);

        do {
            if (w > image.getWidth() || h > image.getHeight()) {
                image = getImage();
                continue;
            }

            int startX = r.nextInt(image.getWidth() - w);
            int startY = r.nextInt(image.getHeight() - h);

            image = image.getSubimage(startX, startY, w, h);
            break;
        } while (true);
    }

    return new LosslessImageContainer(image);
}
 
开发者ID:LabunskyA,项目名称:StegoProxy,代码行数:27,代码来源:PhotoNetRandomPNG.java

示例5: BottomLeftPiece

import java.awt.image.BufferedImage; //导入方法依赖的package包/类
public BottomLeftPiece(TileMap tm) {
	super(tm);
	try {	
		BufferedImage spritesheet = ImageIO.read(
			getClass().getResourceAsStream("/Sprites/Other/ballBatBoss.gif")
		);
		sprites = new BufferedImage[1];
		width = height = 4;
		sprites[0] = spritesheet.getSubimage(0, 10, 10, 10);
		animation.setFrames(sprites);
		animation.setDelay(-1);
	}
	catch(Exception e) {
		e.printStackTrace();
	}
}
 
开发者ID:tonikolaba,项目名称:BatBat-Game,代码行数:17,代码来源:BottomLeftPiece.java

示例6: saveSubImage

import java.awt.image.BufferedImage; //导入方法依赖的package包/类
/**
 * 实现缩放后的截图
 *
 * @param image          缩放后的图像
 * @param subImageBounds 要截取的子图的范围
 * @param subImageFile   要保存的文件
 * @throws IOException
 */
private static void saveSubImage(BufferedImage image,
                                 Rectangle subImageBounds, File subImageFile) throws IOException {
    if (subImageBounds.x < 0 || subImageBounds.y < 0
            || subImageBounds.width - subImageBounds.x > image.getWidth()
            || subImageBounds.height - subImageBounds.y > image.getHeight()) {
        System.out.println("Bad   subimage   bounds");
        return;
    }
    BufferedImage subImage = image.getSubimage(subImageBounds.x,
            subImageBounds.y, subImageBounds.width, subImageBounds.height);
    String fileName = subImageFile.getName();
    String formatName = fileName.substring(fileName.lastIndexOf('.') + 1);
    ImageIO.write(subImage, formatName, subImageFile);
}
 
开发者ID:tong12580,项目名称:OutsourcedProject,代码行数:23,代码来源:ImageUtil.java

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

示例8: fitWidth

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

	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, 0, (height-img.getHeight())/2, null);

	g.dispose();

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

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

示例10: glitchPixels

import java.awt.image.BufferedImage; //导入方法依赖的package包/类
@Override
public byte[] glitchPixels(byte[] inputImageBytes) throws Exception 
{
	int audioBitRate = ((Integer) getPixelGlitchParameters().get("bitRateBlend")).intValue();
	float bitRateBlend = (float) audioBitRate / 10;
	if(bitRateBlend < 0.1F || bitRateBlend > 0.9F)
	{
		return null;
	}
	
	BufferedImage inputImage = ImageUtil.getImageFromBytes(inputImageBytes);
	InputStream imageInputStream = new ByteArrayInputStream(inputImageBytes);
	AudioInputStream distortionAudioStream = new AudioInputStream(imageInputStream, new AudioFormat(AudioFormat.Encoding.ULAW, ThreadLocalRandom.current().nextInt(8000,  20000), 8, 5, 9, ThreadLocalRandom.current().nextInt(8000,  20000), true), inputImageBytes.length);
	ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
	AudioSystem.write(distortionAudioStream, Type.WAVE, outputStream);
	BufferedImage outputImage = new BufferedImage(inputImage.getWidth(), inputImage.getHeight(), BufferedImage.TYPE_4BYTE_ABGR);
	byte[] imageData = ((DataBufferByte) outputImage.getRaster().getDataBuffer()).getData();
	System.arraycopy(outputStream.toByteArray(),0,imageData,0,outputStream.toByteArray().length);
	int[] abgrOffsets = {3, 2, 1, 0}; 
	DataBuffer outputBuffer = new DataBufferByte(imageData, imageData.length);
    WritableRaster raster = Raster.createInterleavedRaster(outputBuffer, inputImage.getWidth(), inputImage.getHeight(), 4 * inputImage.getWidth(), 4, abgrOffsets, null);
    ColorModel colorModel = new ComponentColorModel(ColorSpace.getInstance(ColorSpace.CS_sRGB), true, false, Transparency.TRANSLUCENT, DataBuffer.TYPE_BYTE);
    BufferedImage rasterizedImage = new BufferedImage(colorModel, raster, colorModel.isAlphaPremultiplied(), null);
    rasterizedImage = resizeImage(rasterizedImage, inputImage.getWidth() * 4, inputImage.getHeight() * 4);
    Graphics2D g2d = rasterizedImage.createGraphics();
    g2d.setComposite(AlphaComposite.SrcOver.derive(bitRateBlend));
    g2d.drawImage(inputImage, 0, 0, null);
    g2d.dispose();
    rasterizedImage = rasterizedImage.getSubimage(0, 0, inputImage.getWidth(), inputImage.getHeight());
	return ImageUtil.getImageBytes(rasterizedImage);
}
 
开发者ID:scriptkittie,项目名称:GlitchKernel,代码行数:32,代码来源:DataAsSound.java

示例11: blurredImage

import java.awt.image.BufferedImage; //导入方法依赖的package包/类
/**
 * Applies a gaussian blur of the given radius to the given {@link BufferedImage} using a kernel
 * convolution.
 *
 * @param source The source image.
 * @param radius The blur radius, in pixels.
 * @return A new, blurred image, or the source image if no blur is performed.
 */
public static BufferedImage blurredImage(BufferedImage source, double radius) {
    if (radius == 0) {
        return source;
    }
    final int r = (int) Math.ceil(radius);
    final int rows = r * 2 + 1;
    final float[] kernelData = new float[rows * rows];
    final double sigma = radius / 3;
    final double sigma22 = 2 * sigma * sigma;
    final double sqrtPiSigma22 = Math.sqrt(Math.PI * sigma22);
    final double radius2 = radius * radius;
    double total = 0;
    int index = 0;
    double distance2;
    int x, y;
    for (y = -r; y <= r; y++) {
        for (x = -r; x <= r; x++) {
            distance2 = 1.0 * x * x + 1.0 * y * y;
            if (distance2 > radius2) {
                kernelData[index] = 0;
            } else {
                kernelData[index] = (float) (Math.exp(-distance2 / sigma22) / sqrtPiSigma22);
            }
            total += kernelData[index];
            ++index;
        }
    }
    for (index = 0; index < kernelData.length; index++) {
        kernelData[index] /= total;
    }
    // We first pad the image so the kernel can operate at the edges.
    BufferedImage paddedSource = paddedImage(source, r);
    BufferedImage blurredPaddedImage = operatedImage(paddedSource, new ConvolveOp(
            new Kernel(rows, rows, kernelData), ConvolveOp.EDGE_ZERO_FILL, null));
    return blurredPaddedImage.getSubimage(r, r, source.getWidth(), source.getHeight());
}
 
开发者ID:RaysonYeungHK,项目名称:Svg2AndroidXml,代码行数:45,代码来源:AssetUtil.java

示例12: sprites

import java.awt.image.BufferedImage; //导入方法依赖的package包/类
/**
 * Constructs and returns the sprites in the sprite sheet
 *
 * @return The sprites in the sprite sheet
 */
public Image[][] sprites() {
    if (sprites == null) {
        sprites = new Image[4][3];
        BufferedImage sheet = Azmata.imageFromFile(sheet_path);
        for (int i = 0; i < 4; i++) {
            for (int j = 0; j < 3; j++) {
                sprites[i][j] = sheet.getSubimage(j * Azmata.BLOCK_SIZE, i * Azmata.BLOCK_SIZE, Azmata.BLOCK_SIZE, Azmata.BLOCK_SIZE);
            }
        }
    }
    return sprites;
}
 
开发者ID:Jeffmagma,项目名称:Azmata,代码行数:18,代码来源:SpriteSheet.java

示例13: getSelectionFromCanvas

import java.awt.image.BufferedImage; //导入方法依赖的package包/类
/**
 * Make the canvas image bounded by the given selection shape the current selected image.
 */
protected void getSelectionFromCanvas() {
    getCanvas().clearScratch();

    Shape selectionBounds = getSelectionOutline();
    BufferedImage maskedSelection = maskSelection(getCanvas().getCanvasImage(), selectionBounds);
    BufferedImage trimmedSelection = maskedSelection.getSubimage(selectionBounds.getBounds().x, selectionBounds.getBounds().y, selectionBounds.getBounds().width, selectionBounds.getBounds().height);

    selectedImage.set(trimmedSelection);
    redrawSelection();
}
 
开发者ID:defano,项目名称:jmonet,代码行数:14,代码来源:AbstractSelectionTool.java

示例14: downloadNapchart

import java.awt.image.BufferedImage; //导入方法依赖的package包/类
static synchronized File downloadNapchart(String chart, File f) throws IOException
{
	if (f.exists())
	{
		charts.add(chart);
		return f;
	}
	else
	{
		try
		{
			/*
			driver.get("https://napchart.com/" + chart);
			File screenshot = ((TakesScreenshot) driver).getScreenshotAs(OutputType.FILE);
			*/
			File screenshot = File.createTempFile("napchart", "png");
			FileUtils.copyURLToFile(new URL("https://napchart.com/api/getImage?chartid=" + chart + "&width=600&height=600&shape=circle"), screenshot);
			BufferedImage image = ImageIO.read(screenshot);
			screenshot.delete();
			/*
			WebElement canvas = driver.findElement(By.className("canvas"));
			Point canvasLocation = canvas.getLocation();
			int canvasWidth = canvas.getSize().getWidth();
			int canvasHeight = canvas.getSize().getHeight();
			BufferedImage eleScreenshot = image.getSubimage(canvasLocation.getX(), canvasLocation.getY(), canvasWidth, canvasHeight);
			*/
			BufferedImage eleScreenshot = image.getSubimage(20, 0, 560, 600); // slight edge crop
			ImageIO.write(eleScreenshot, "png", f);
			charts.add(chart);
		}
		catch (Throwable t)
		{
			throw new IOException("Failed to download image from napchart.com", t);
		}
	}
	return f;
}
 
开发者ID:PolyphasicDevTeam,项目名称:NapBot,代码行数:38,代码来源:NapchartHandler.java

示例15: getScreenshot

import java.awt.image.BufferedImage; //导入方法依赖的package包/类
@Override
public BufferedImage getScreenshot(WebDriver wd) {
    if(Objects.nonNull(topElementToRemove)) {
        calculateHeaderSizeToCut(wd);
    }
    JavascriptExecutor js = (JavascriptExecutor) wd;

    int allH = getFullHeight(wd);
    int allW = getFullWidth(wd);
    int winH = getWindowHeight(wd);

    winH = winH - headerToCut;
    int scrollTimes = allH / winH;
    int tail = allH - winH * scrollTimes;

    BufferedImage finalImage = new BufferedImage(allW, allH, BufferedImage.TYPE_4BYTE_ABGR);
    Graphics2D graphics = finalImage.createGraphics();

    js.executeScript("scroll(0, arguments[0])", 0);
    BufferedImage firstPart = simple().getScreenshot(wd);
    graphics.drawImage(firstPart, 0, 0, null);

    for (int n = 1; n < scrollTimes; n++) {
        js.executeScript("scroll(0, arguments[0])", winH * n);
        BufferedImage part = getHeaderCutImage(wd);
        graphics.drawImage(part, 0, n * winH + headerToCut, null);
    }

    if (tail > 0) {
        js.executeScript("scroll(0, document.body.scrollHeight)");
        BufferedImage last = getHeaderCutImage(wd);
        BufferedImage tailImage = last.getSubimage(0, last.getHeight() - tail, last.getWidth(), tail);
        graphics.drawImage(tailImage, 0, scrollTimes * winH, null);
    }
    graphics.dispose();

    return finalImage;
}
 
开发者ID:willhaben,项目名称:willtest,代码行数:39,代码来源:FixedTopBarShootingStrategy.java


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