本文整理匯總了Java中javafx.scene.image.PixelWriter.setPixels方法的典型用法代碼示例。如果您正苦於以下問題:Java PixelWriter.setPixels方法的具體用法?Java PixelWriter.setPixels怎麽用?Java PixelWriter.setPixels使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類javafx.scene.image.PixelWriter
的用法示例。
在下文中一共展示了PixelWriter.setPixels方法的9個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: resizeCanvas
import javafx.scene.image.PixelWriter; //導入方法依賴的package包/類
public static Image resizeCanvas(Image imageSource, int newWidth, int newHeight, int offsetX, int offsetY) {
int sourceWidth = (int) imageSource.getWidth();
int sourceHeight = (int) imageSource.getHeight();
// No work needed here...
if (sourceWidth == newWidth && sourceHeight == newHeight)
return imageSource;
WritableImage outputImage = new WritableImage(newWidth, newHeight);
PixelReader pixelReader = imageSource.getPixelReader();
PixelWriter pixelWriter = outputImage.getPixelWriter();
WritablePixelFormat<IntBuffer> format = WritablePixelFormat.getIntArgbInstance();
int[] buffer = new int[sourceWidth * sourceHeight];
pixelReader.getPixels(0, 0, sourceWidth, sourceHeight, format, buffer, 0, sourceWidth);
pixelWriter.setPixels(offsetX, offsetY, sourceWidth, sourceHeight, format, buffer, 0, sourceWidth);
return outputImage;
}
示例2: generateLeft
import javafx.scene.image.PixelWriter; //導入方法依賴的package包/類
/**
* Generates the left preview of the skin
* @param skin The skin image
* @param cape The cape image
* @return The generated preview image
*/
public static Image generateLeft(Image skin, Image cape) {
double h = skin.getHeight();
PixelReader pr = skin.getPixelReader();
WritableImage wi = new WritableImage(8, 32);
PixelWriter pw = wi.getPixelWriter();
if (h == 64) { // New format
//MAIN ZONES
//Head
pw.setPixels(0, 0, 8, 8, pr, 16, 8);
//Left Arm
pw.setPixels(2, 8, 4, 12, pr, 40, 52);
//Left Leg
pw.setPixels(2, 20, 4, 12, pr, 24, 52);
//EXTRA ZONES
//Head
renderLayer(0, 0, 8, 8, pr, pw, 48, 8);
//Left Arm
renderLayer(2, 8, 4, 12, pr, pw, 56, 52);
//Left Leg
renderLayer(2, 20, 4, 12, pr, pw, 8, 52);
} else if (h == 32) { //Legacy format
//Head
pw.setPixels(0, 0, 8, 8, pr, 16, 8);
//Hat
renderLayer(0, 0, 8, 8, pr, pw, 48, 8);
//Left Arm
renderLayerInverse(2, 8, 4, 12, pr, pw, 40, 20);
//Left Leg
renderLayerInverse(2, 20, 4, 12, pr, pw, 0, 20);
}
if (cape != null) {
PixelReader pr2 = cape.getPixelReader();
pw.setPixels(6, 8, 1, 16, pr2, 0, 1);
}
return wi;
}
示例3: generateRight
import javafx.scene.image.PixelWriter; //導入方法依賴的package包/類
/**
* Generates the right preview of the skin
* @param skin The skin image
* @param cape The cape image
* @return The generated preview image
*/
public static Image generateRight(Image skin, Image cape) {
double h = skin.getHeight();
PixelReader pr = skin.getPixelReader();
WritableImage wi = new WritableImage(8, 32);
PixelWriter pw = wi.getPixelWriter();
if (h == 64) { // New format
//MAIN ZONES
//Head
pw.setPixels(0, 0, 8, 8, pr, 0, 8);
//Right Arm
pw.setPixels(2, 8, 4, 12, pr, 40, 20);
//Right Leg
pw.setPixels(2, 20, 4, 12, pr, 0, 20);
//EXTRA ZONES
//Head
renderLayer(0, 0, 8, 8, pr, pw, 32, 8);
//Right Arm
renderLayer(2, 8, 4, 12, pr, pw, 40, 36);
//Right Leg
renderLayer(2, 20, 4, 12, pr, pw, 0, 36);
} else if (h == 32) { //Legacy format
//Head
pw.setPixels(0, 0, 8, 8, pr, 0, 8);
//Hat
renderLayer(0, 0, 8, 8, pr, pw, 32, 8);
//Right Arm
pw.setPixels(2, 8, 4, 12, pr,40, 20);
//Right Leg
pw.setPixels(2, 20, 4, 12, pr, 0, 20);
}
if (cape != null) {
PixelReader pr2 = cape.getPixelReader();
pw.setPixels(1, 8, 1, 16, pr2, 11, 1);
}
return wi;
}
示例4: applyEffect
import javafx.scene.image.PixelWriter; //導入方法依賴的package包/類
private Image applyEffect() {
int a,b, i=oldInd;
oldInd=newInd;
newInd=i;
i=0;
mapInd=oldInd;
for (int y=0;y<height;y++) {
for (int x=0;x<width;x++) {
short data = (short)((waterMap[mapInd-width]+waterMap[mapInd+width]+
waterMap[mapInd-1]+waterMap[mapInd+1])>>1);
data -= waterMap[newInd+i];
data -= data>>4;
waterMap[newInd+i]=data;
data = (short)(1024-data);
a=((x-halfWidth)*data/1024)+halfWidth;
if (a>=width){ a=width-1; }
if (a<0){ a=0; }
b=((y-halfHeight)*data/1024)+halfHeight;
if (b>=height){ b=height-1; }
if (b<0){ b=0; }
water[i++]=original[a+(b*width)];
mapInd++;
}
}
WritableImage raster = new WritableImage(width, height);
PixelWriter pixelWriter = raster.getPixelWriter();
pixelWriter.setPixels(0,0,width,height,
PixelFormat.getIntArgbInstance(),water, 0,width);
return raster;
}
示例5: pixelate
import javafx.scene.image.PixelWriter; //導入方法依賴的package包/類
private void pixelate(final DotMatrix MATRIX, final boolean WITH_RED, final boolean WITH_GREEN, final boolean WITH_BLUE) {
PixelReader reader = src.getPixelReader();
PixelWriter writer = dst.getPixelWriter();
WritablePixelFormat<IntBuffer> format = WritablePixelFormat.getIntArgbInstance();
int width = (int) src.getWidth();
int height = (int) src.getHeight();
int kernelSize = 6;
for (int y = kernelSize; y < height - kernelSize * 2; y += kernelSize * 2 + 1) {
for (int x = kernelSize; x < width - kernelSize * 2; x += kernelSize * 2 + 1) {
int kernelWidth = kernelSize * 2 + 1;
int kernelHeight = kernelSize * 2 + 1;
int[] buffer = new int[kernelWidth * kernelHeight];
reader.getPixels(x, y, kernelWidth, kernelHeight, format, buffer, 0, kernelWidth);
int alpha = 0;
int red = 0;
int green = 0;
int blue = 0;
for (int color : buffer) {
alpha += (color >>> 24);
red += (color >>> 16 & 0xFF);
green += (color >>> 8 & 0xFF);
blue += (color & 0xFF);
}
alpha = alpha / kernelWidth / kernelHeight;
red = WITH_RED ? red / kernelWidth / kernelHeight : 0;
green = WITH_GREEN ? green / kernelWidth / kernelHeight : 0;
blue = WITH_BLUE ? blue / kernelWidth / kernelHeight : 0;
int pixelateColor = (alpha << 24) + (red << 16) + (green << 8) + blue;
Arrays.fill(buffer, pixelateColor);
writer.setPixels(x, y, kernelWidth, kernelHeight, format, buffer, 0, kernelWidth);
MATRIX.setPixel(x / kernelWidth, y / kernelHeight, pixelateColor);
}
}
}
示例6: pixelate
import javafx.scene.image.PixelWriter; //導入方法依賴的package包/類
private void pixelate() {
PixelReader reader = src.getPixelReader();
PixelWriter writer = dst.getPixelWriter();
WritablePixelFormat<IntBuffer> format = WritablePixelFormat.getIntArgbInstance();
int width = (int) src.getWidth();
int height = (int) src.getHeight();
// Bird Demo
// int kernelSize = 4;
// Han Solo Demo
int kernelSize = 6;
for (int y = kernelSize; y < height - kernelSize * 2; y += kernelSize * 2 + 1) {
for (int x = kernelSize; x < width - kernelSize * 2; x += kernelSize * 2 + 1) {
int kernelWidth = kernelSize * 2 + 1;
int kernelHeight = kernelSize * 2 + 1;
int[] buffer = new int[kernelWidth * kernelHeight];
reader.getPixels(x, y, kernelWidth, kernelHeight, format, buffer, 0, kernelWidth);
int alpha = 0;
int red = 0;
int green = 0;
int blue = 0;
for (int color : buffer) {
alpha += (color >>> 24);
red += (color >>> 16 & 0xFF);
green += (color >>> 8 & 0xFF);
blue += (color & 0xFF);
}
alpha = alpha / kernelWidth / kernelHeight;
red = red / kernelWidth / kernelHeight;
green = green / kernelWidth / kernelHeight;
blue = blue / kernelWidth / kernelHeight;
int pixelateColor = (alpha << 24) + (red << 16) + (green << 8) + blue;
Arrays.fill(buffer, pixelateColor);
writer.setPixels(x, y, kernelWidth, kernelHeight, format, buffer, 0, kernelWidth);
matrix.setPixel(x / kernelWidth, y / kernelHeight, pixelateColor);
}
}
addText();
}
示例7: paintRectangularBrick
import javafx.scene.image.PixelWriter; //導入方法依賴的package包/類
private void paintRectangularBrick(PixelWriter pixelWriter, int startX, int startY, ColoredBrick coloredBrick) {
final int bytesPerPixel = 4;
Brick brick = coloredBrick.getBrick();
boolean[][] matrix = brick.getMatrix();
final int pixelsPerRow = drawnBasicBrickPixelWidth * matrix[0].length;
byte[] bgraRenderedBrick = renderedBrick.get(coloredBrick);
if (bgraRenderedBrick == null) {
Color rgb = coloredBrick.getColor().getRGB();
byte r, g, b, a;
r = MathUtils.colorComponentToByte(rgb.getRed());
g = MathUtils.colorComponentToByte(rgb.getGreen());
b = MathUtils.colorComponentToByte(rgb.getBlue());
a = MathUtils.colorComponentToByte(rgb.getOpacity());
bgraRenderedBrick = new byte[matrix[0].length * matrix.length * drawnBasicBrickPixelHeight * drawnBasicBrickPixelWidth * bytesPerPixel];
renderedBrick.put(coloredBrick, bgraRenderedBrick);
// fill with the regular color
for (int i = 0; i < bgraRenderedBrick.length; i += bytesPerPixel) {
bgraRenderedBrick[i] = b;
bgraRenderedBrick[i + 1] = g;
bgraRenderedBrick[i + 2] = r;
bgraRenderedBrick[i + 3] = a;
}
if (threeDEffect) {
Color colorDark = rgb.darker();
Color colorLight = rgb.brighter();
byte rDark, gDark, bDark, aDark;
byte rLight, gLight, bLight, aLight;
rDark = MathUtils.colorComponentToByte(colorDark.getRed());
gDark = MathUtils.colorComponentToByte(colorDark.getGreen());
bDark = MathUtils.colorComponentToByte(colorDark.getBlue());
aDark = a;
rLight = MathUtils.colorComponentToByte(colorLight.getRed());
gLight = MathUtils.colorComponentToByte(colorLight.getGreen());
bLight = MathUtils.colorComponentToByte(colorLight.getBlue());
aLight = a;
//border left
fillRectBgra(bgraRenderedBrick, bLight, gLight, rLight, aLight, 0, 2, 2, drawnBasicBrickPixelHeight * matrix.length - 2, pixelsPerRow);
//border top
fillRectBgra(bgraRenderedBrick, bLight, gLight, rLight, aLight, 0, 0, pixelsPerRow - 2, 2, pixelsPerRow);
//border right
fillRectBgra(bgraRenderedBrick, bDark, gDark, rDark, aDark, pixelsPerRow - 2,
0,
2,
drawnBasicBrickPixelHeight * matrix.length,
pixelsPerRow);
//border bottom
fillRectBgra(bgraRenderedBrick, bDark, gDark, rDark, aDark, 2,
drawnBasicBrickPixelHeight * matrix.length - 2,
pixelsPerRow - 2,
2,
pixelsPerRow);
}
}
PixelFormat<ByteBuffer> pixelFormat = PixelFormat.getByteBgraPreInstance();
pixelWriter.setPixels(startX, startY, pixelsPerRow, matrix.length * drawnBasicBrickPixelHeight, pixelFormat, bgraRenderedBrick, 0, pixelsPerRow * bytesPerPixel);
}
示例8: generateFront
import javafx.scene.image.PixelWriter; //導入方法依賴的package包/類
/**
* Generates the front preview of the skin
* @param skin The skin image
* @param cape The cape image
* @param slim If the format is slim
* @return The generated preview image
*/
public static Image generateFront(Image skin, Image cape, boolean slim) {
double h = skin.getHeight();
PixelReader pr = skin.getPixelReader();
WritableImage wi = new WritableImage(slim && h == 64 ? 14 : 16, 32);
PixelWriter pw = wi.getPixelWriter();
if (h == 64) { // New format
//MAIN ZONES
//Head
pw.setPixels(slim ? 3 : 4, 0, 8, 8, pr, 8, 8);
//Right Arm
pw.setPixels(0, 8, slim ? 3 : 4, 12, pr, 44, 20);
//Left Arm
pw.setPixels(slim ? 11 : 12, 8, slim ? 3 : 4, 12, pr, 36, 52);
//Body
pw.setPixels(slim ? 3 : 4, 8, 8, 12, pr, 20, 20);
//Right Leg
pw.setPixels(slim ? 3 : 4, 20, 4, 12, pr, 4, 20);
//Left Leg
pw.setPixels(slim ? 7 : 8, 20, 4, 12, pr, 20, 52);
//EXTRA ZONES
//Head
renderLayer(slim ? 3 : 4, 0, 8, 8, pr, pw, 40, 8);
//Right Arm
renderLayer(0, 8, slim ? 3 : 4, 12, pr, pw, 44, 36);
//Left Arm
renderLayer(slim ? 11 : 12, 8, slim ? 3 : 4, 12, pr, pw, 52, 52);
//Body
renderLayer(slim ? 3 : 4, 8, 8, 12, pr, pw, 20, 36);
//Right Leg
renderLayer(slim ? 3 : 4, 20, 4, 12, pr, pw, 4, 36);
//Left Leg
renderLayer(slim ? 7 : 8, 20, 4, 12, pr, pw, 4, 52);
} else if (h == 32) {
//Head
pw.setPixels(4, 0, 8, 8, pr, 8, 8);
//Hat
renderLayer(4, 0, 8, 8, pr, pw, 40, 8);
//Right Arm
pw.setPixels(0, 8, 4, 12, pr, 44, 20);
//Left Arm
renderLayerInverse(12, 8, 4, 12, pr, pw,44, 20);
//Body
pw.setPixels(4, 8, 8, 12, pr, 20, 20);
//Right Leg
pw.setPixels(4, 20, 4, 12, pr, 4, 20);
//Left Leg
renderLayerInverse(8, 20, 4, 12, pr, pw, 4, 20);
}
if (cape != null) {
PixelReader pr2 = cape.getPixelReader();
pw.setPixels(slim && h == 64 ? 2 : 3, 20, 1, 4, pr2, 12, 1);
pw.setPixels(slim && h == 64 ? 11 : 12, 20, 1, 4, pr2, 21, 1);
}
return wi;
}
示例9: generateBack
import javafx.scene.image.PixelWriter; //導入方法依賴的package包/類
/**
* Generates the back preview of the skin
* @param skin The skin image
* @param cape The cape image
* @param slim If the format is slim
* @return The generated preview image
*/
public static Image generateBack(Image skin, Image cape, boolean slim) {
double h = skin.getHeight();
PixelReader pr = skin.getPixelReader();
WritableImage wi = new WritableImage(slim && h == 64 ? 14 : 16, 32);
PixelWriter pw = wi.getPixelWriter();
if (h == 64) { // New format
//MAIN ZONES
//Head
pw.setPixels(slim ? 3 : 4, 0, 8, 8, pr, 24, 8);
//Right Arm
pw.setPixels(slim ? 11 : 12, 8, slim ? 3 : 4, 12, pr, slim ? 51 : 52, 20);
//Left Arm
pw.setPixels(0, 8, slim ? 3 : 4, 12, pr, slim ? 43 : 44, 52);
//Body
pw.setPixels(slim ? 3 : 4, 8, 8, 12, pr, 32, 20);
//Right Leg
pw.setPixels(slim ? 7 : 8, 20, 4, 12, pr, 12, 20);
//Left Leg
pw.setPixels(slim ? 3 : 4, 20, 4, 12, pr, 28, 52);
//EXTRA ZONES
//Head
renderLayer(slim ? 3 : 4, 0, 8, 8, pr, pw, 56, 8);
//Right Arm
renderLayer(slim ? 11 : 12, 8, slim ? 3 : 4, 12, pr, pw, slim ? 51 : 52, 36);
//Left Arm
renderLayer(0, 8, slim ? 3 : 4, 12, pr, pw, slim ? 59 : 60, 52);
//Body
renderLayer(slim ? 3 : 4, 8, 8, 12, pr, pw, 32, 36);
//Right Leg
renderLayer(slim ? 7 : 8, 20, 4, 12, pr, pw, 12, 36);
//Left Leg
renderLayer(slim ? 3 : 4, 20, 4, 12, pr, pw, 12, 52);
} else if (h == 32) { //Legacy format
//Head
pw.setPixels(4, 0, 8, 8, pr, 24, 8);
//Hat
renderLayer(4, 0, 8, 8, pr, pw, 56, 8);
//Right Arm
pw.setPixels(12, 8, 4, 12, pr, 52, 20);
//Left Arm
renderLayerInverse(0, 8, 4, 12, pr, pw,52, 20);
//Body
pw.setPixels(4, 8, 8, 12, pr, 32, 20);
//Right Leg
pw.setPixels(8, 20, 4, 12, pr, 12, 20);
//Left Leg
renderLayerInverse(4, 20, 4, 12, pr, pw, 12, 20);
}
if (cape != null) {
PixelReader pr2 = cape.getPixelReader();
pw.setPixels(slim && h == 64 ? 2 : 3, 8, 10, 16, pr2, 1, 1);
}
return wi;
}