本文整理汇总了Java中java.awt.image.WritableRaster.setPixel方法的典型用法代码示例。如果您正苦于以下问题:Java WritableRaster.setPixel方法的具体用法?Java WritableRaster.setPixel怎么用?Java WritableRaster.setPixel使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类java.awt.image.WritableRaster
的用法示例。
在下文中一共展示了WritableRaster.setPixel方法的11个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: processaAlgoritmo
import java.awt.image.WritableRaster; //导入方法依赖的package包/类
public BufferedImage processaAlgoritmo(BufferedImage img, PosicoesDTO posicoes) {
WritableRaster raster = img.getRaster();
BufferedImage newImage = new BufferedImage(img.getWidth(), img.getHeight(), BufferedImage.TYPE_INT_RGB);
int pixels[] = new int[4];
for (int i = posicoes.getX1(); i < posicoes.getY1() - 1; i++) {
for (int j = posicoes.getX2(); j < posicoes.getY2() - 1; j++) {
raster.getPixel(i, j, pixels);
int[] novosPixels = calculaPixeis(img, i, j);
pixels[0] = novosPixels[0];
pixels[1] = novosPixels[1];
pixels[2] = novosPixels[2];
raster.setPixel(i, j, pixels);
}
}
newImage.setData(raster);
return newImage;
}
示例2: fromColorCubeMatrix
import java.awt.image.WritableRaster; //导入方法依赖的package包/类
/**
* Converts a color cube matrix into a BufferedImage. See {@link #toColorCubeMatrix(BufferedImage)} for the
* format details of the color cube matrix.
*
* @param matrix The matrix to convert into an image
* @return The BufferedImage resulting from the given color cube matrix
*/
private static BufferedImage fromColorCubeMatrix(double[][][] matrix) {
BufferedImage restored = new BufferedImage(matrix[0].length, matrix.length, BufferedImage.TYPE_INT_ARGB);
WritableRaster raster = restored.getRaster();
for (int y = 0; y < matrix.length; y++) {
for (int x = 0; x < matrix[y].length; x++) {
double[] pixel = matrix[y][x];
pixel[0] *= 255;
pixel[1] *= 255;
pixel[2] *= 255;
pixel[3] = matrix[y][x][3];
pixel[0] = pixel[0] < 0 ? 0 : pixel[0] > 255 ? 255 : pixel[0];
pixel[1] = pixel[1] < 0 ? 0 : pixel[1] > 255 ? 255 : pixel[1];
pixel[2] = pixel[2] < 0 ? 0 : pixel[2] > 255 ? 255 : pixel[2];
raster.setPixel(x, y, pixel);
}
}
return restored;
}
示例3: createAnBlankAndWhitePngImage
import java.awt.image.WritableRaster; //导入方法依赖的package包/类
@Test
public void createAnBlankAndWhitePngImage() throws IOException {
int m = 5;
int n = 5;
BufferedImage image = new BufferedImage(m, n, BufferedImage.TYPE_BYTE_BINARY);
WritableRaster raster = image.getRaster();
for (int x = 0; x < m; x++) {
for (int y = 0; y < m; y++) {
int index = (x + y) % 2 == 0 ? 1: 0;
raster.setPixel(x, y, new int[]{ index });
}
}
File output = new File("src/test/resources/png-test.black-white.png");
ImageIO.write(image, "png", output);
}
示例4: createAnGrayPngImage
import java.awt.image.WritableRaster; //导入方法依赖的package包/类
@Test
public void createAnGrayPngImage() throws IOException {
int m = 5;
int n = 5;
BufferedImage image = new BufferedImage(m, n, BufferedImage.TYPE_BYTE_GRAY);
WritableRaster raster = image.getRaster();
for (int x = 0; x < m; x++) {
for (int y = 0; y < m; y++) {
int index = 51 * x + 10*y;
raster.setPixel(x, y, new int[]{ index });
}
}
File output = new File("src/test/resources/png-test.gray.png");
ImageIO.write(image, "png", output);
}
示例5: runTest
import java.awt.image.WritableRaster; //导入方法依赖的package包/类
public void runTest(Object context, int numReps) {
WritableRaster ras = ((Context) context).ras;
int pixeldata[] = ((Context) context).pixeldata;
do {
ras.setPixel(numReps&7, 0, pixeldata);
} while (--numReps > 0);
}
示例6: girar
import java.awt.image.WritableRaster; //导入方法依赖的package包/类
public BufferedImage girar(BufferedImage img, PosicoesDTO posicoes) {
WritableRaster raster = img.getRaster();
BufferedImage newImage = new BufferedImage(img.getWidth(), img.getHeight(), BufferedImage.TYPE_INT_RGB);
WritableRaster rasterNewImage = newImage.getRaster();
int pixels[] = new int[4];
for (int i = posicoes.getX1(); i < posicoes.getX2(); i++) {
for (int j = posicoes.getY1(); j < posicoes.getY2(); j++) {
raster.getPixel(i, j, pixels);
rasterNewImage.setPixel(i, img.getHeight() - j, pixels);
}
}
newImage.setData(rasterNewImage);
return newImage;
}
示例7: girar
import java.awt.image.WritableRaster; //导入方法依赖的package包/类
public BufferedImage girar(BufferedImage img, PosicoesDTO posicoes) {
WritableRaster raster = img.getRaster();
BufferedImage newImage = new BufferedImage(img.getWidth(), img.getHeight(), BufferedImage.TYPE_INT_RGB);
WritableRaster rasterNewImage = newImage.getRaster();
int pixels[] = new int[4];
for (int i = 1; i < img.getWidth() - 1; i++) {
for (int j = 1; j < img.getHeight() - 1; j++) {
raster.getPixel(i, j, pixels);
rasterNewImage.setPixel(i, j, pixels);
}
}
for (int i = posicoes.getX1(); i < posicoes.getX2(); i++) {
int pixeisInvertidos = 0;
for (int j = posicoes.getY1(); j < posicoes.getY2(); j++) {
raster.getPixel(i, j, pixels);
rasterNewImage.setPixel(i, posicoes.getY2() - pixeisInvertidos, pixels);
pixeisInvertidos++;
}
}
newImage.setData(rasterNewImage);
return newImage;
}
示例8: generateIdenticon
import java.awt.image.WritableRaster; //导入方法依赖的package包/类
/**
* Code taken from: <a href="https://stackoverflow.com/a/40699460">Stackoverflow answer from Kevin G. based on code from davidhampgonsalves.com/Identicons</a>
* Comments and slight modifications added.
*/
public static javafx.scene.image.Image generateIdenticon(String text, int image_width, int image_height) throws IOException {
// If the input name/text is null or empty no image can be created.
if (text == null || text.length() < 3) {
return null;
}
int width = 5, height = 5;
byte[] hash = text.getBytes();
BufferedImage identicon = new BufferedImage(width, height, BufferedImage.TYPE_INT_ARGB);
WritableRaster raster = identicon.getRaster();
int [] background = new int [] {255,255,255, 0};
int [] foreground = new int [] {hash[0] & 255, hash[1] & 255, hash[2] & 255, 255};
for(int x=0 ; x < width ; x++) {
//Enforce horizontal symmetry
int i = x < 3 ? x : 4 - x;
for(int y=0 ; y < height; y++) {
int [] pixelColor;
//toggle pixels based on bit being on/off
if((hash[i] >> y & 1) == 1)
pixelColor = foreground;
else
pixelColor = background;
raster.setPixel(x, y, pixelColor);
}
}
BufferedImage finalImage = new BufferedImage(image_width, image_height, BufferedImage.TYPE_INT_ARGB);
//Scale image to the size you want
AffineTransform at = new AffineTransform();
at.scale(image_width / width, image_height / height);
AffineTransformOp op = new AffineTransformOp(at, AffineTransformOp.TYPE_NEAREST_NEIGHBOR);
finalImage = op.filter(identicon, finalImage);
// Convert BufferedImage to javafx image
return createImage(finalImage);
}
示例9: paintOverArea
import java.awt.image.WritableRaster; //导入方法依赖的package包/类
/**
* change an area of pixels around a pixel to a specified color
*/
private static void paintOverArea(int centerX, int centerY, int areaSize, Color color, WritableRaster raster) {
for (int x = centerX - areaSize; x < raster.getWidth() && x < centerX + areaSize; x++) {
x = x < 0 ? 0 : x; // ArrayOutOfBound protection
for (int y = centerY - areaSize; y < raster.getHeight() && y < centerY + areaSize; y++) {
y = y < 0 ? 0 : y; // ArrayOutOfBound protection
int[] strip = getPixelValue(raster, x, y);
changeColor(strip, color);
raster.setPixel(x, y, strip);
}
}
}
示例10: makeGrayscaleImage
import java.awt.image.WritableRaster; //导入方法依赖的package包/类
public static BufferedImage makeGrayscaleImage(float[][] mat) {
mat = padAndNormalize(mat);
final BufferedImage img = new BufferedImage(Math.min(mat.length, maxDim), Math.min(mat[0].length, maxDim), BufferedImage.TYPE_BYTE_GRAY);
WritableRaster writeableRaster = img.getRaster();
for (int i=0; i<writeableRaster.getWidth(); ++i) {
for (int j=0; j<writeableRaster.getHeight(); ++j) {
writeableRaster.setPixel(i, writeableRaster.getHeight()-1-j, new float[] { mat[i][j] * 255 });
}
}
return img;
}
示例11: putPixel
import java.awt.image.WritableRaster; //导入方法依赖的package包/类
/** put pixel */
private void putPixel(WritableRaster raster, int x, int y, Color color) {
//Debug.log("setPixel("+x+","+y+","+color+")");
raster.setPixel(
x, y,
new int[] { color.getRed(), color.getGreen(), color.getBlue() });
}