本文整理了Java中java.awt.image.BufferedImage.setRGB()
方法的一些代码示例,展示了BufferedImage.setRGB()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。BufferedImage.setRGB()
方法的具体详情如下:
包路径:java.awt.image.BufferedImage
类名称:BufferedImage
方法名:setRGB
[英]Sets a pixel in this BufferedImage
to the specified RGB value. The pixel is assumed to be in the default RGB color model, TYPE_INT_ARGB, and default sRGB color space. For images with an IndexColorModel
, the index with the nearest color is chosen.
[中]将此BufferedImage
中的像素设置为指定的RGB值。假定该像素位于默认RGB颜色模型、类型_INT_ARGB和默认sRGB颜色空间中。对于具有IndexColorModel
的图像,将选择具有最接近颜色的索引。
代码示例来源:origin: libgdx/libgdx
static private void plot (BufferedImage dst, int x, int y, int argb) {
if (0 <= x && x < dst.getWidth() && 0 <= y && y < dst.getHeight()) dst.setRGB(x, y, argb);
}
代码示例来源:origin: graphhopper/graphhopper
public BufferedImage getImageFromArray(int[] pixels, int width, int height) {
BufferedImage tmpImage = new BufferedImage(width, height, BufferedImage.TYPE_INT_ARGB_PRE);
tmpImage.setRGB(0, 0, width, height, pixels, 0, width);
return tmpImage;
}
代码示例来源:origin: MovingBlocks/Terasology
public void storeGreyscaleMapIntoAlpha(BufferedImage imageWithoutAlpha, BufferedImage greyscaleImage) {
int width = imageWithoutAlpha.getWidth();
int height = imageWithoutAlpha.getHeight();
int[] imagePixels = imageWithoutAlpha.getRGB(0, 0, width, height, null, 0, width);
int[] maskPixels = greyscaleImage.getRGB(0, 0, width, height, null, 0, width);
for (int i = 0; i < imagePixels.length; i++) {
int color = imagePixels[i] & 0x00ffffff; // Mask preexisting alpha
int alpha = maskPixels[i] << 24; // Shift blue to alpha
imagePixels[i] = color | alpha;
}
imageWithoutAlpha.setRGB(0, 0, width, height, imagePixels, 0, width);
}
代码示例来源:origin: plantuml/plantuml
public UImage toUImage(ColorMapper colorMapper, HtmlColor backcolor, HtmlColor forecolor) {
final BufferedImage im = new BufferedImage(width, height, BufferedImage.TYPE_INT_RGB);
if (backcolor == null) {
backcolor = HtmlColorUtils.WHITE;
}
if (forecolor == null) {
forecolor = HtmlColorUtils.BLACK;
}
final HtmlColorGradient gradient = new HtmlColorGradient(backcolor, forecolor, '\0');
for (int col = 0; col < width; col++) {
for (int line = 0; line < height; line++) {
final int localColor = color[line][col];
if (localColor == -1) {
final double coef = 1.0 * grey[line][col] / (16 - 1);
final Color c = gradient.getColor(colorMapper, coef);
im.setRGB(col, line, c.getRGB());
} else {
im.setRGB(col, line, localColor);
}
}
}
return new UImage(im);
}
代码示例来源:origin: kevin-wayne/algs4
/**
* Creates a new grayscale picture that is a deep copy of the argument picture.
*
* @param picture the picture to copy
* @throws IllegalArgumentException if {@code picture} is {@code null}
*/
public GrayscalePicture(GrayscalePicture picture) {
if (picture == null) throw new IllegalArgumentException("constructor argument is null");
width = picture.width();
height = picture.height();
image = new BufferedImage(width, height, BufferedImage.TYPE_INT_RGB);
filename = picture.filename;
isOriginUpperLeft = picture.isOriginUpperLeft;
for (int col = 0; col < width(); col++)
for (int row = 0; row < height(); row++)
image.setRGB(col, row, picture.image.getRGB(col, row));
}
代码示例来源:origin: plantuml/plantuml
public void setPixel(int pX, int pY, Color pColor) {
fEarthImage2.setRGB(pX, pY, pColor.getRGB());
}
代码示例来源:origin: haraldk/TwelveMonkeys
@Test
public void testNotBadCaching() throws IOException {
T reader = createReader();
TestData data = getTestData().get(0);
reader.setInput(data.getInputStream());
BufferedImage one = reader.read(0);
BufferedImage two = reader.read(0);
assertNotSame("Multiple reads return same (mutable) image", one, two);
one.setRGB(0, 0, Color.BLUE.getRGB());
two.setRGB(0, 0, Color.RED.getRGB());
assertTrue(one.getRGB(0, 0) != two.getRGB(0, 0));
reader.dispose();
}
代码示例来源:origin: libgdx/libgdx
public BufferedImage processImage (BufferedImage image, int maxIterations) {
int width = image.getWidth();
int height = image.getHeight();
BufferedImage processedImage = new BufferedImage(width, height, BufferedImage.TYPE_INT_ARGB);
int[] rgb = image.getRGB(0, 0, width, height, null, 0, width);
Mask mask = new Mask(rgb);
int iterations = 0;
int lastPending = -1;
while (mask.pendingSize > 0 && mask.pendingSize != lastPending && iterations < maxIterations) {
lastPending = mask.pendingSize;
executeIteration(rgb, mask, width, height);
iterations++;
}
processedImage.setRGB(0, 0, width, height, rgb, 0, width);
return processedImage;
}
代码示例来源:origin: plantuml/plantuml
public static void managePattern(UParam param, Graphics2D g2d) {
final UPattern pattern = param.getPattern();
if (pattern == UPattern.VERTICAL_STRIPE) {
final BufferedImage bi = new BufferedImage(4, 4, BufferedImage.TYPE_INT_ARGB);
final Rectangle r = new Rectangle(0, 0, 4, 4);
final int rgb = ((HtmlColorSimple) param.getBackcolor()).getColor999().getRGB();
for (int i = 0; i < 4; i++) {
for (int j = 0; j < 4; j++) {
if (i == 0 || i == 1) {
bi.setRGB(i, j, rgb);
final BufferedImage bi = new BufferedImage(4, 4, BufferedImage.TYPE_INT_ARGB);
final Rectangle r = new Rectangle(0, 0, 4, 4);
final int rgb = ((HtmlColorSimple) param.getBackcolor()).getColor999().getRGB();
for (int i = 0; i < 4; i++) {
for (int j = 0; j < 4; j++) {
if (j == 0 || j == 1) {
bi.setRGB(i, j, rgb);
final BufferedImage bi = new BufferedImage(4, 4, BufferedImage.TYPE_INT_ARGB);
final Rectangle r = new Rectangle(0, 0, 4, 4);
final int rgb = ((HtmlColorSimple) param.getBackcolor()).getColor999().getRGB();
bi.setRGB(0, 1, rgb);
bi.setRGB(1, 0, rgb);
bi.setRGB(1, 1, rgb);
bi.setRGB(1, 2, rgb);
bi.setRGB(2, 1, rgb);
g2d.setPaint(new TexturePaint(bi, r));
代码示例来源:origin: runelite/runelite
public BufferedImage toBufferedImage()
{
int[] transPixels = new int[pixels.length];
BufferedImage img = new BufferedImage(width, height, BufferedImage.TYPE_INT_ARGB);
for (int i = 0; i < pixels.length; i++)
{
if (pixels[i] != 0)
{
transPixels[i] = pixels[i] | 0xff000000;
}
}
img.setRGB(0, 0, width, height, transPixels, 0, width);
return img;
}
代码示例来源:origin: libgdx/libgdx
static private void plot (BufferedImage dst, int x, int y, int argb) {
if (0 <= x && x < dst.getWidth() && 0 <= y && y < dst.getHeight()) dst.setRGB(x, y, argb);
}
代码示例来源:origin: kevin-wayne/algs4
/**
* Creates a new picture that is a deep copy of the argument picture.
*
* @param picture the picture to copy
* @throws IllegalArgumentException if {@code picture} is {@code null}
*/
public Picture(Picture picture) {
if (picture == null) throw new IllegalArgumentException("constructor argument is null");
width = picture.width();
height = picture.height();
image = new BufferedImage(width, height, BufferedImage.TYPE_INT_RGB);
filename = picture.filename;
isOriginUpperLeft = picture.isOriginUpperLeft;
for (int col = 0; col < width(); col++)
for (int row = 0; row < height(); row++)
image.setRGB(col, row, picture.image.getRGB(col, row));
}
代码示例来源:origin: jphp-group/jphp
@Signature
public void setPixel(int x, int y, Color color) {
image.setRGB(x, y, color.getRGB());
}
代码示例来源:origin: libgdx/libgdx
public BufferedImage processImage (BufferedImage image, int maxIterations) {
int width = image.getWidth();
int height = image.getHeight();
BufferedImage processedImage = new BufferedImage(width, height, BufferedImage.TYPE_INT_ARGB);
int[] rgb = image.getRGB(0, 0, width, height, null, 0, width);
Mask mask = new Mask(rgb);
int iterations = 0;
int lastPending = -1;
while (mask.pendingSize > 0 && mask.pendingSize != lastPending && iterations < maxIterations) {
lastPending = mask.pendingSize;
executeIteration(rgb, mask, width, height);
iterations++;
}
processedImage.setRGB(0, 0, width, height, rgb, 0, width);
return processedImage;
}
代码示例来源:origin: plantuml/plantuml
public UImage toUImage(ColorMapper colorMapper, HtmlColor backcolor, HtmlColor color) {
if (backcolor == null) {
backcolor = HtmlColorUtils.WHITE;
}
if (color == null) {
color = HtmlColorUtils.BLACK;
}
// if (backcolor instanceof HtmlColorGradient) {
// return special(colorMapper, (HtmlColorGradient) backcolor, color);
// }
final BufferedImage im = new BufferedImage(width, height, BufferedImage.TYPE_INT_RGB);
final HtmlColorGradient gradient = new HtmlColorGradient(backcolor, color, '\0');
for (int col = 0; col < width; col++) {
for (int line = 0; line < height; line++) {
final double coef = 1.0 * grey[line][col] / (grayLevel - 1);
final Color c = gradient.getColor(colorMapper, coef);
im.setRGB(col, line, c.getRGB());
}
}
return new UImage(im);
}
代码示例来源:origin: MovingBlocks/Terasology
/**
* Transforms ByteBuffer into BufferedImage with specified width and height.
*/
private BufferedImage convertByteBufferToBufferedImage(ByteBuffer buffer, int width, int height) {
BufferedImage image = new BufferedImage(width, height, BufferedImage.TYPE_INT_RGB);
for (int x = 0; x < width; x++) {
for (int y = 0; y < height; y++) {
int i = (x + width * y) * 4;
int r = buffer.get(i) & 0xFF;
int g = buffer.get(i + 1) & 0xFF;
int b = buffer.get(i + 2) & 0xFF;
image.setRGB(x, height - (y + 1), (0xFF << 24) | (r << 16) | (g << 8) | b);
}
}
return image;
}
代码示例来源:origin: runelite/runelite
@Inject
@Override
public void toBufferedImage(BufferedImage img)
{
int width = getWidth();
int height = getHeight();
if (img.getWidth() != width || img.getHeight() != height)
{
throw new IllegalArgumentException("Image bounds do not match SpritePixels");
}
int[] pixels = getPixels();
int[] transPixels = new int[pixels.length];
for (int i = 0; i < pixels.length; i++)
{
if (pixels[i] != 0)
{
transPixels[i] = pixels[i] | 0xff000000;
}
}
img.setRGB(0, 0, width, height, transPixels, 0, width);
}
代码示例来源:origin: loklak/loklak_server
final int height2 = ruy - loy + 1;
boolean border = false;
final BufferedImage image2 = new BufferedImage(width2, height2, BufferedImage.TYPE_INT_RGB);
rgb = this.image.getRGB(i - 1, j);
border = (rgb == bgcolor);
rgbR += rgb >> 16 & 0xff;
rgb = this.image.getRGB(i, j - 1);
border = border || (rgb == bgcolor);
rgbR += rgb >> 16 & 0xff;
rgb = this.image.getRGB(i + 1, j);
border = border || (rgb == bgcolor);
rgbR += rgb >> 16 & 0xff;
image2.setRGB(i-lox, j-loy, rgb);
代码示例来源:origin: kevin-wayne/algs4
/**
* Sets the color of pixel ({@code col}, {@code row}) to the given grayscale value.
*
* @param col the column index
* @param row the row index
* @param color the color (converts to grayscale if color is not a shade of gray)
* @throws IllegalArgumentException unless both {@code 0 <= col < width} and {@code 0 <= row < height}
* @throws IllegalArgumentException if {@code color} is {@code null}
*/
public void set(int col, int row, Color color) {
validateColumnIndex(col);
validateRowIndex(row);
if (color == null) throw new IllegalArgumentException("color argument is null");
Color gray = toGray(color);
image.setRGB(col, row, gray.getRGB());
}
代码示例来源:origin: stackoverflow.com
public static void makeGray(BufferedImage img)
{
for (int x = 0; x < img.getWidth(); ++x)
for (int y = 0; y < img.getHeight(); ++y)
{
int rgb = img.getRGB(x, y);
int r = (rgb >> 16) & 0xFF;
int g = (rgb >> 8) & 0xFF;
int b = (rgb & 0xFF);
int grayLevel = (r + g + b) / 3;
int gray = (grayLevel << 16) + (grayLevel << 8) + grayLevel;
img.setRGB(x, y, gray);
}
}
内容来源于网络,如有侵权,请联系作者删除!