本文整理汇总了Java中javafx.scene.image.WritablePixelFormat类的典型用法代码示例。如果您正苦于以下问题:Java WritablePixelFormat类的具体用法?Java WritablePixelFormat怎么用?Java WritablePixelFormat使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
WritablePixelFormat类属于javafx.scene.image包,在下文中一共展示了WritablePixelFormat类的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Java代码示例。
示例1: resizeCanvas
import javafx.scene.image.WritablePixelFormat; //导入依赖的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;
}
开发者ID:RPTools,项目名称:tokentool,代码行数:20,代码来源:ImageUtil.java
示例2: getPixels
import javafx.scene.image.WritablePixelFormat; //导入依赖的package包/类
@Override
public int[] getPixels(Image img, int x, int y, int w, int h)
{
int[] pixels = new int[w * h];
PixelReader reader = img.getPixelReader();
PixelFormat.Type type = reader.getPixelFormat().getType();
WritablePixelFormat<IntBuffer> format = null;
if(type == PixelFormat.Type.INT_ARGB_PRE)
{
format = PixelFormat.getIntArgbPreInstance();
}
else
{
format = PixelFormat.getIntArgbInstance();
}
reader.getPixels(x, y, w, h, format, pixels, 0, w);
return pixels;
}
开发者ID:freeseawind,项目名称:NinePatch,代码行数:25,代码来源:FxNinePatch.java
示例3: getAssociatedPixelFormat
import javafx.scene.image.WritablePixelFormat; //导入依赖的package包/类
/**
* Determine the appropriate {@link WritablePixelFormat} type that can be
* used to transfer data into the indicated BufferedImage.
*
* @param bimg
* the BufferedImage that will be used as a destination for a
* {@code PixelReader<IntBuffer>#getPixels()} operation.
* @return
*/
private static WritablePixelFormat<IntBuffer> getAssociatedPixelFormat(BufferedImage bimg) {
switch (bimg.getType()) {
// We lie here for xRGB, but we vetted that the src data was opaque
// so we can ignore the alpha. We use ArgbPre instead of Argb
// just to get a loop that does not have divides in it if the
// PixelReader happens to not know the data is opaque.
case BufferedImage.TYPE_INT_RGB:
case BufferedImage.TYPE_INT_ARGB_PRE:
return PixelFormat.getIntArgbPreInstance();
case BufferedImage.TYPE_INT_ARGB:
return PixelFormat.getIntArgbInstance();
default:
// Should not happen...
throw new InternalError("Failed to validate BufferedImage type");
}
}
开发者ID:phrack,项目名称:ShootOFF,代码行数:28,代码来源:SwingFXUtils.java
示例4: fromFXImage
import javafx.scene.image.WritablePixelFormat; //导入依赖的package包/类
/**
* Snapshots the specified JavaFX {@link Image} object and stores a copy of
* its pixels into a {@link BufferedImage} object, creating a new object if
* needed. The method will only convert a JavaFX {@code Image} that is
* readable as per the conditions on the {@link Image#getPixelReader()
* Image.getPixelReader()} method. If the {@code Image} is not readable, as
* determined by its {@code getPixelReader()} method, then this method will
* return null. If the {@code Image} is a writable, or other dynamic image,
* then the {@code BufferedImage} will only be set to the current state of
* the pixels in the image as determined by its {@link PixelReader}. Further
* changes to the pixels of the {@code Image} will not be reflected in the
* returned {@code BufferedImage}.
* <p>
* The optional {@code BufferedImage} parameter may be reused to store the
* copy of the pixels. A new {@code BufferedImage} will be created if the
* supplied object is null, is too small or of a type which the image pixels
* cannot be easily converted into.
*
* @param img
* the JavaFX {@code Image} to be converted
* @param bimg
* an optional {@code BufferedImage} object that may be used to
* store the returned pixel data
* @return a {@code BufferedImage} containing a snapshot of the JavaFX
* {@code Image}, or null if the {@code Image} is not readable.
* @since JavaFX 2.2
*/
public static BufferedImage fromFXImage(Image img, BufferedImage bimg) {
PixelReader pr = img.getPixelReader();
if (pr == null) {
return null;
}
int iw = (int) img.getWidth();
int ih = (int) img.getHeight();
int prefBimgType = getBestBufferedImageType(pr.getPixelFormat(), bimg);
if (bimg != null) {
int bw = bimg.getWidth();
int bh = bimg.getHeight();
if (bw < iw || bh < ih || bimg.getType() != prefBimgType) {
bimg = null;
} else if (iw < bw || ih < bh) {
Graphics2D g2d = bimg.createGraphics();
g2d.setComposite(AlphaComposite.Clear);
g2d.fillRect(0, 0, bw, bh);
g2d.dispose();
}
}
if (bimg == null) {
bimg = new BufferedImage(iw, ih, prefBimgType);
}
IntegerComponentRaster icr = (IntegerComponentRaster) bimg.getRaster();
int offset = icr.getDataOffset(0);
int scan = icr.getScanlineStride();
int data[] = icr.getDataStorage();
WritablePixelFormat<IntBuffer> pf = getAssociatedPixelFormat(bimg);
pr.getPixels(0, 0, iw, ih, pf, data, offset, scan);
return bimg;
}
开发者ID:phrack,项目名称:ShootOFF,代码行数:67,代码来源:SwingFXUtils.java
示例5: pixelate
import javafx.scene.image.WritablePixelFormat; //导入依赖的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);
}
}
}
开发者ID:HanSolo,项目名称:matriximage,代码行数:42,代码来源:Main2.java
示例6: pixelate
import javafx.scene.image.WritablePixelFormat; //导入依赖的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();
}
开发者ID:HanSolo,项目名称:matriximage,代码行数:47,代码来源:Main.java
注:本文中的javafx.scene.image.WritablePixelFormat类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论