• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

Java WritablePixelFormat类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了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;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Java SystemKeyspace类代码示例发布时间:2022-05-22
下一篇:
Java JavaUtils类代码示例发布时间:2022-05-22
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap