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


Java BufferedImage.setRGB方法代码示例

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


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

示例1: createTestImage

import java.awt.image.BufferedImage; //导入方法依赖的package包/类
private static ImageInputStream createTestImage(int type) throws IOException  {
    int w = 100;
    int h = 100;

    BufferedImage img = new BufferedImage(w, h, type);

    int dx = w / colors.length;

    for (int i = 0; i < colors.length; i++) {
        for (int x = i *dx; (x < (i + 1) * dx) && (x < w) ; x++) {
            for (int y = 0; y < h; y++) {
                img.setRGB(x, y, colors[i].getRGB());
            }
        }
    }

    File pwd = new File(".");
    File out = File.createTempFile("rgba_", ".png", pwd);
    System.out.println("Create file: " + out.getAbsolutePath());
    ImageIO.write(img, "PNG", out);
    return ImageIO.createImageInputStream(out);
}
 
开发者ID:lambdalab-mirror,项目名称:jdk8u-jdk,代码行数:23,代码来源:PngOutputTypeTest.java

示例2: testCopySrcIntoDstAt4

import java.awt.image.BufferedImage; //导入方法依赖的package包/类
@Test ()
public void testCopySrcIntoDstAt4()
{
    System.out.println("copySrcIntoDstAt: send image with 1 pixel(RGB), expects 1 pixel(RGB)");

    BufferedImage src = new BufferedImage(1, 1, BufferedImage.TYPE_3BYTE_BGR);
    src.setRGB(0, 0, 10);

    BufferedImage dst = new BufferedImage(1, 1, BufferedImage.TYPE_3BYTE_BGR);

    Utils.copySrcIntoDstAt(src, dst);

    DataBufferByte expected = (DataBufferByte) src.getRaster().getDataBuffer();
    DataBufferByte result = (DataBufferByte) dst.getRaster().getDataBuffer();

    assertArrayEquals(expected.getData(), result.getData());
}
 
开发者ID:buni-rock,项目名称:Pixie,代码行数:18,代码来源:UtilsTest.java

示例3: getTexture

import java.awt.image.BufferedImage; //导入方法依赖的package包/类
@Override
public BufferedImage getTexture(double seed) {
	mainColor = new Color(128,128,128);
	
	BufferedImage bi = new BufferedImage(TextureGenerator.TEX_W, TextureGenerator.TEX_H, BufferedImage.TYPE_4BYTE_ABGR);
	Color c;
	for(int i = 0;i < bi.getWidth();i++) {
		for(int j = 0;j < bi.getHeight();j++) {
			c = TextureGenerator.fade(mainColor,TextureGenerator.trick(mainColor, -10),Math.abs(VMath.mod(i-j,32)-16)/16);

			//strength != 0 && weakStrength != 0 ? trick(mainc,turbulence(i+3.1f,j+3.1f,1,seed)*80) : mainc;
			bi.setRGB(i, j, c.getRGB());
		}
	}
	return bi;
}
 
开发者ID:vanyle,项目名称:Explorium,代码行数:17,代码来源:BlockStone.java

示例4: createImage

import java.awt.image.BufferedImage; //导入方法依赖的package包/类
private static BufferedImage createImage(String content, String imgPath,
        boolean needCompress) throws Exception {
    Hashtable hints = new Hashtable();
    hints.put(EncodeHintType.ERROR_CORRECTION, ErrorCorrectionLevel.H);
    hints.put(EncodeHintType.CHARACTER_SET, CHARSET);
    hints.put(EncodeHintType.MARGIN, 1);
    BitMatrix bitMatrix = new MultiFormatWriter().encode(content,
            BarcodeFormat.QR_CODE, QRCODE_SIZE, QRCODE_SIZE, hints);
    int width = bitMatrix.getWidth();
    int height = bitMatrix.getHeight();
    BufferedImage image = new BufferedImage(width, height,
            BufferedImage.TYPE_INT_RGB);
    for (int x = 0; x < width; x++) {
        for (int y = 0; y < height; y++) {
            image.setRGB(x, y, bitMatrix.get(x, y) ? 0xFF000000
                    : 0xFFFFFFFF);
        }
    }
    if (imgPath == null || "".equals(imgPath)) {
        return image;
    }
 // 插入图片
    CodeUtil.insertImage(image, imgPath, needCompress);
    return image;
}
 
开发者ID:Fetax,项目名称:Fetax-AI,代码行数:26,代码来源:CodeUtil.java

示例5: makeIcon

import java.awt.image.BufferedImage; //导入方法依赖的package包/类
private static Image makeIcon(long hIcon, boolean getLargeIcon) {
    if (hIcon != 0L && hIcon != -1L) {
        // Get the bits.  This has the side effect of setting the imageHash value for this object.
        final int[] iconBits = getIconBits(hIcon);
        if (iconBits != null) {
            // icons are always square
            final int size = (int) Math.sqrt(iconBits.length);
            final int baseSize = getLargeIcon ? 32 : 16;
            final BufferedImage img =
                    new BufferedImage(size, size, BufferedImage.TYPE_INT_ARGB);
            img.setRGB(0, 0, size, size, iconBits, 0, size);
            return size == baseSize
                    ? img
                    : new MultiResolutionIconImage(baseSize, img);
        }
    }
    return null;
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:19,代码来源:Win32ShellFolder2.java

示例6: getTexture

import java.awt.image.BufferedImage; //导入方法依赖的package包/类
@Override
public BufferedImage getTexture(double seed) {
	mainColor = new Color(139,69,19);
	
	BufferedImage bi = new BufferedImage(TextureGenerator.TEX_W, TextureGenerator.TEX_H, BufferedImage.TYPE_4BYTE_ABGR);
	Color c;
	for(int i = 0;i < bi.getWidth();i++) {
		for(int j = 0;j < bi.getHeight();j++) {
			c = TextureGenerator.fade(mainColor,TextureGenerator.trick(mainColor,-40),Math.abs(VMath.mod(i-j,32)-16)/16);

			//strength != 0 && weakStrength != 0 ? trick(mainc,turbulence(i+3.1f,j+3.1f,1,seed)*80) : mainc;
			bi.setRGB(i, j, c.getRGB());
		}
	}
	return bi;
}
 
开发者ID:vanyle,项目名称:Explorium,代码行数:17,代码来源:BlockDirt.java

示例7: 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:binarywang,项目名称:qrcode-utils,代码行数:26,代码来源:BufferedImageLuminanceSource.java

示例8: read

import java.awt.image.BufferedImage; //导入方法依赖的package包/类
protected void read(InputStream in, BufferedImage dst) throws IOException {
  final int w = dst.getWidth();
  final int h = dst.getHeight();

  final byte[] bytes = new byte[4*w];
  final ByteBuffer bb = ByteBuffer.wrap(bytes);

  final int[] row = new int[w];

  for (int y = 0; y < h; ++y) {
    // read the row from the stream
    IOUtils.read(in, bytes);

    // convert the bytes to an int[]
    bb.asIntBuffer().get(row);

    // write the row back to the image
    dst.setRGB(0, y, w, 1, row, 0, w);
  }
}
 
开发者ID:ajmath,项目名称:VASSAL-src,代码行数:21,代码来源:FileImageTypeConverter.java

示例9: convertBiMatrix2Img

import java.awt.image.BufferedImage; //导入方法依赖的package包/类
public static BufferedImage convertBiMatrix2Img(byte[][] biMatrix, int nLeft, int nTop, int nWidth, int nHeight)	{
	if (biMatrix == null || biMatrix.length == 0 || biMatrix[0].length == 0)	{
		return null;	// we cannot create a zero width zero height bitmap.
	}
	int width = Math.min(nWidth, biMatrix.length - nLeft);
	int height = Math.min(nHeight, biMatrix[0].length - nTop);
	int[] colorMatrix = new int[width * height];
	for (int idx = 0; idx < height; idx ++)	{
		for (int idx1 = 0; idx1 < width; idx1 ++)	{
			if (biMatrix[idx1 + nLeft][idx + nTop] == 0)	{
				colorMatrix[idx * width + idx1] = Color.WHITE.getRGB();
			} else	{
				colorMatrix[idx * width + idx1] = Color.BLACK.getRGB();
			}
		}
	}

       // Initialize BufferedImage, assuming Color[][] is already properly populated.
       BufferedImage bufferedImage = new BufferedImage(width, height, BufferedImage.TYPE_INT_RGB);

       // Set each pixel of the BufferedImage to the color from the Color[][].
       for (int x = 0; x < width; x++) {
           for (int y = 0; y < height; y++) {
               bufferedImage.setRGB(x, y, colorMatrix[y * width + x]);
           }
       }		
	return bufferedImage;
}
 
开发者ID:woshiwpa,项目名称:JMathImgProc,代码行数:29,代码来源:ImageMgr.java

示例10: convert

import java.awt.image.BufferedImage; //导入方法依赖的package包/类
@Override
public ResultImage[] convert(BufferedImage original) {
    OptionsObject oo = OptionsObject.getInstance();
    BufferedImage output = ImageHelper.copyImage(original);
    final BufferedImage output1 = new BufferedImage(output.getWidth(), output.getHeight(), BufferedImage.TYPE_INT_ARGB);
    final BufferedImage output2 = new BufferedImage(output.getWidth(), output.getHeight(), BufferedImage.TYPE_INT_ARGB);

    // Dithers the images to the GigaScreen palette (if/else to switch between preview window images and actual output)
    ResultImage[] resultImage = imageConverter.convert(output);
    output = resultImage[0].getImage();

    // Algorithm replaces each pixel with the colour from the closest matching
    // 4 colour GigaScreen attribute block.
    GigaScreenAttribute[][] quad = getGigaScreenAttribute(output);
    GigaScreenAttribute combo = null;
    for (int y = 0; y < output.getHeight(); ++y) {
        for (int x = 0; x < output.getWidth(); ++x) {
            if (x % ATTRIBUTE_BLOCK_SIZE == 0) {
                combo = quad[x / ATTRIBUTE_BLOCK_SIZE][y / ATTRIBUTE_BLOCK_SIZE];
            }
            GigaScreenAttribute.GigaScreenColour c = ColourHelper.getClosestGigaScreenColour(output.getRGB(x, y), combo);
            output.setRGB(x, y, c.getGigascreenColour());
            output1.setRGB(x, y, c.getScreen1Colour());
            output2.setRGB(x, y, c.getScreen2Colour());
        }
    }

    if (oo.getExportTape() || oo.getExportScreen()) {
        orderByGigaScreenPaletteOrder(output1, output2);
    }

    return new ResultImage[]{new ResultImage(ResultImageType.FINAL_IMAGE, output),
            new ResultImage(ResultImageType.SUPPORTING_IMAGE, output1),
            new ResultImage(ResultImageType.SUPPORTING_IMAGE, output2)};
}
 
开发者ID:KodeMunkie,项目名称:imagetozxspec,代码行数:36,代码来源:GigaScreenConverterImpl.java

示例11: subImages

import java.awt.image.BufferedImage; //导入方法依赖的package包/类
/**
 * Subtracts img2 from img1
 */
BufferedImage subImages(BufferedImage img1, BufferedImage img2) {
    if (img1.getHeight() != img2.getHeight() ||
            img1.getWidth() != img2.getWidth()) {
        throw new RuntimeException("Different sizes");
    }
    BufferedImage ret = new BufferedImage(img1.getWidth(), img1.getHeight(), img1.getType());

    for (int x = 0; x < ret.getWidth(); x++) {
        for (int y = 0; y < ret.getHeight(); y++) {
            ret.setRGB(x, y, subPixels(img1.getRGB(x, y), img2.getRGB(x, y)));
        }
    }
    return ret;
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:18,代码来源:bug8016833.java

示例12: subtractImage

import java.awt.image.BufferedImage; //导入方法依赖的package包/类
/**
 * Subtracts subimage from image. Could be used to save file difference for
 * future analysis.
 *
 * @param minuend an image to subtract from.
 * @param deduction an image to subtract.
 * @param relativeX - deduction-in-minuend X coordinate
 * @param relativeY - deduction-in-minuend Y coordinate
 * @return a result image.
 */
public static BufferedImage subtractImage(BufferedImage minuend, BufferedImage deduction, int relativeX, int relativeY) {
    int mWidth = minuend.getWidth();
    int mHeight = minuend.getHeight();
    int dWidth = deduction.getWidth();
    int dHeight = deduction.getHeight();

    int maxWidth = (mWidth > relativeX + dWidth) ? mWidth : (relativeX + dWidth);
    int maxHeight = (mHeight > relativeY + dHeight) ? mHeight : (relativeY + dHeight);

    BufferedImage result = new BufferedImage(maxWidth, maxHeight, BufferedImage.TYPE_INT_RGB);
    int mColor, dColor;
    for (int x = 0; x < maxWidth; x++) {
        for (int y = 0; y < maxHeight; y++) {
            if (x >= mWidth
                    || y >= mHeight) {
                mColor = 0;
            } else {
                mColor = minuend.getRGB(x, y);
            }
            if (x >= dWidth + relativeX
                    || y >= dHeight + relativeY
                    || x < relativeX
                    || y < relativeY) {
                dColor = 0;
            } else {
                dColor = deduction.getRGB(x - relativeX, y - relativeY);
            }
            result.setRGB(x, y, subtractColors(mColor, dColor));
        }
    }
    return result;
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:43,代码来源:ImageTool.java

示例13: initVistaDragTextureImage

import java.awt.image.BufferedImage; //导入方法依赖的package包/类
/**
 * Dynamically creates and returns drag texture icon
 */
private static final Icon initVistaDragTextureImage() {
    BufferedImage i = new BufferedImage(2, 2, BufferedImage.TYPE_INT_RGB);
    int grey = new Color(124,124,124).getRGB();
    i.setRGB(1, 0, grey);
    i.setRGB(0, 1, grey);
    i.setRGB(0, 0, new Color(162,163,164).getRGB());
    i.setRGB(1, 1, new Color(107,107,107).getRGB());
    return new ImageIcon(i);
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:13,代码来源:ColorUtil.java

示例14: exportData

import java.awt.image.BufferedImage; //导入方法依赖的package包/类
private void exportData() throws IOException {
	PreviewController controller = Lookup.getDefault().lookup(
			PreviewController.class);
	PreviewProperties props = controller.getModel(workspace)
			.getProperties();

	props.putValue(PreviewProperty.VISIBILITY_RATIO, 1.0);
	props.putValue("width", width);
	props.putValue("height", height);
	props.putValue(PreviewProperty.MARGIN, margin);
	// props.putValue(PreviewProperty.EDGE_CURVED, false);

	controller.refreshPreview(workspace);

	ProcessingTarget target = (ProcessingTarget) controller
			.getRenderTarget(RenderTarget.PROCESSING_TARGET, workspace);

	target.refresh();

	PGraphicsJava2D pg2 = (PGraphicsJava2D) target.getGraphics();
	BufferedImage img = new BufferedImage(width, height,
			BufferedImage.TYPE_INT_RGB);
	img.setRGB(0, 0, width, height, pg2.pixels, 0, width);
	ImageIO.write(img, "jpg", outputStream);

	outputStream.close();
	props.removeSimpleValue(PreviewProperty.VISIBILITY_RATIO);
	props.removeSimpleValue("width");
	props.removeSimpleValue("height");
	props.removeSimpleValue(PreviewProperty.MARGIN);
}
 
开发者ID:dev-cuttlefish,项目名称:cuttlefish,代码行数:32,代码来源:JPEGExporter.java

示例15: distributeError

import java.awt.image.BufferedImage; //导入方法依赖的package包/类
public void distributeError(BufferedImage output, int oldPixel, int newPixel, int x, int y, Integer boundX, Integer boundY) {
	if (isInBounds(output, x+1, y, boundX, boundY)) {output.setRGB(x+1, y, calculateAdjustedRGB(oldPixel, newPixel, output.getRGB(x+1, y), TWENTY_FOURTH));}
	if (isInBounds(output, x+2, y, boundX, boundY)) {output.setRGB(x+2, y, calculateAdjustedRGB(oldPixel, newPixel, output.getRGB(x+2, y), TWENTY_FOURTH));}
	if (isInBounds(output, x-1, y+1, boundX, boundY)) {output.setRGB(x-1, y+1, calculateAdjustedRGB(oldPixel, newPixel, output.getRGB(x-1, y+1), TWENTY_FOURTH));}
	if (isInBounds(output, x, y+1, boundX, boundY)) {output.setRGB(x, y+1, calculateAdjustedRGB(oldPixel, newPixel, output.getRGB(x, y+1), TWENTY_FOURTH));}
	if (isInBounds(output, x+1, y+1, boundX, boundY)) {output.setRGB(x+1, y+1, calculateAdjustedRGB(oldPixel, newPixel, output.getRGB(x+1, y+1), TWENTY_FOURTH));}
	if (isInBounds(output, x, y+2, boundX, boundY)) {output.setRGB(x, y+2, calculateAdjustedRGB(oldPixel, newPixel, output.getRGB(x, y+2), TWENTY_FOURTH));}
}
 
开发者ID:KodeMunkie,项目名称:imagetozxspec,代码行数:9,代码来源:LowErrorAtkinsonDitherStrategy.java


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