没有任何平滑处理的 JavaFX ImageView [英] JavaFX ImageView without any smoothing

查看:30
本文介绍了没有任何平滑处理的 JavaFX ImageView的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否可以在不应用任何平滑的情况下在 JavaFX 2.2 的 ImageView 中渲染缩放图像?我使用 setSmooth(false) 将 50x50 图像渲染为 200x200 ImageView,因此源图像中的每个像素都应映射到屏幕上的 4x4 正方形.

然而,生成的渲染仍然在所有 16 个目标像素上平滑源像素.有谁知道无需手动将每个像素复制到新图像中的方法?

解决方案

在 JavaFX 2.2 中 ImageView 总是会做一些平滑,而不管 以生成上述输出.

<小时>

更新有关实现自己的图像过滤器的想法

JavaFX Effect 与用于图像加载例程的过滤器不同,尽管可以创建过滤图像的 Effect.在 JavaFX 2.2 中公开记录的 API 支持创建自定义效果,因此创建自定义效果可能会很困难.

用于图像支持的本机代码是最近的作为 openjfx 项目 的一部分开源,所以你可以看看它是如何过滤的目前正在实施.

您可能还想针对 JavaFX 运行时项目提交功能请求以允许我们我们自己的 2D 过滤器".

Is it possible to render a scaled image in an ImageView in JavaFX 2.2 without any smoothing applied? I'm rendering a 50x50 image into a 200x200 ImageView, with setSmooth(false), so each pixel in the source image should map to a 4x4 square on the screen.

However, the resulting render still smooths the source pixel across all 16 destination pixels. Does anyone know of a way to do this without manually copying over each pixel into a new image?

解决方案

In JavaFX 2.2 ImageView is always going to do some smoothing regardless of the smooth hint you provide to the ImageView.

(Based on testing using Java 7u15 and Windows 7 with an ATI HD4600 graphics card).

Perhaps it is a bug that ImageView will always smooth the Image, but the documentation doesn't really specify exactly what smoothing does or doesn't do, so it's hard to say what its real intent is. You may want to post a reference to this question to the openjfx-dev mailing list or log an issue in the JavaFX issue tracker to get a more expert opinion from a developer.


I tried a few different methods for scaling the Image:

  1. Scale in the Image constructor.
  2. Scale in ImageView with fitWidth/fitHeight.
  3. Scale by using the scaleX/scaleY properties on an ImageView.
  4. Scale by sampling the Image with a PixelReader and creating a new Image with a PixelWriter.

I found that methods 1 & 4 resulted in a sharp pixelated image as you wish for and 2 & 3 resulted in a blurry aliased image.

Sample code to generate the above output.


Update with ideas on implementing your own image filter

A JavaFX Effect is not the same as the Filter used for the Image loading routines, though an Effect to filter an image could be created. In JavaFX 2.2 publicly documented API to support creation of custom effects, so creating of a custom effect may prove difficult.

The native code for image support was recently open sourced as part of the openjfx project, so you could look at that to see how the filtering is currently implemented.

You may also want to file a feature request against the JavaFX runtime project to "allow us to make our own 2D filters".

这篇关于没有任何平滑处理的 JavaFX ImageView的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆