當前位置: 首頁>>代碼示例>>Java>>正文


Java WritableRaster.setPixel方法代碼示例

本文整理匯總了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;

}
 
開發者ID:nbfontana,項目名稱:pdi,代碼行數:22,代碼來源:ProcessadorImagem.java

示例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;
}
 
開發者ID:defano,項目名稱:jmonet,代碼行數:31,代碼來源:FloydSteinberg.java

示例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);
}
 
開發者ID:fifth-postulate,項目名稱:finding-the-planets,代碼行數:18,代碼來源:ImageTest.java

示例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);
}
 
開發者ID:fifth-postulate,項目名稱:finding-the-planets,代碼行數:18,代碼來源:ImageTest.java

示例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);
}
 
開發者ID:lambdalab-mirror,項目名稱:jdk8u-jdk,代碼行數:8,代碼來源:PixelTests.java

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

}
 
開發者ID:nbfontana,項目名稱:pdi,代碼行數:18,代碼來源:GiraImagem.java

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

}
 
開發者ID:nbfontana,項目名稱:pdi,代碼行數:27,代碼來源:GiraImagemParcial.java

示例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);
}
 
開發者ID:Gurgy,項目名稱:Cypher,代碼行數:46,代碼來源:Util.java

示例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);
        }
    }
}
 
開發者ID:BlackCraze,項目名稱:GameResourceBot,代碼行數:15,代碼來源:Preprocessor.java

示例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;
  }
 
開發者ID:tberg12,項目名稱:klavier,代碼行數:12,代碼來源:MatrixVis.java

示例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() });
}
 
開發者ID:Jenner4S,項目名稱:unitimes,代碼行數:8,代碼來源:RequiredTimeTable.java


注:本文中的java.awt.image.WritableRaster.setPixel方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。