基于位置的信息交互系统的平台开发外文翻译资料

 2022-05-03 10:05

Have you ever heard someone say, “When two worlds collide”? This expression is used when a person from a different background or culture is put in a situation where they are at odds and must face very hard decisions. When building GUI applications needing graphics or animations, we are often on a collision course between business and gaming worlds. In other words, when developing applications, itrsquo;s nice to strike a good balance of having UI aspects from business applications and video game-like effects.

In the ever-changing world of rich Internet applications (RIA), you probably have noticed an increased use of animations such as pulsing buttons, transitions, moving backgrounds, and so on. GUI applications can use animations to provide visual cues to let the user know what to do next. With JavaFX, you will be able to have the best of both worlds, creating appealing graphics as well as form-based applications handling business transactions.

In this chapter, you will learn about the basics of JavaFX graphics such as displaying and manipulating images. Also, in this chapter you will learn high-level animation APIs. Fasten your seatbelts; yoursquo;ll discover solutions to integrate cool game-like interfaces into everyday applications.

In this chapter, yoursquo;ll learn about the following:

  • Loading and displaying images
  • Background tasks
  • Progress indicators
  • Altering color settings on images
  • Writing bitmapped images to disk
  • Dragging and dropping image files
  • Animation using key values, keyframes, and timelines
  • Animation transition classes
  • Sequential and parallel transitions

Working with Images

Yet another powerful capability in JavaFX is the ability to display standard image file formats on the scene graph. In this section, you learn how to load, display, scale, and rotate images. As a bonus, yoursquo;ll also learn how to easily alter an imagersquo;s color attributes such as its hue, saturation, brightness, and contrast.

After learning about the basics of the JavaFX Image and ImageView APIs, you will get to explore an example of a Photo Viewer application. This fun application allows you to scale, rotate, and manipulate images.

copy; Carl Dea, Gerrit Grunwald, Joseacute; Pereda, Sean Phillips and Mark Heckler 2017 227

C. Dea et al., JavaFX 9 by Example, DOI 10.1007/978-1-4842-1961-4_7

Loading Images

You are probably aware of the many standard image file formats on the Internet, such as .jpg, .png, .gif, and .bmp. To load standard image file formats, JavaFX provides the javafx.scene.image.Image API. The Image class has many convenient constructors that facilitate different loading strategies, as shown in the following list:

  • Image(java.io.InputStream inputStream)
  • Image(java.io.InputStream is, double requestedWidth, double requestedHeight, boolean preserveRatio, boolean smooth)
  • Image(java.lang.String url)
  • Image(java.lang.String url, boolean backgroundLoading)
  • Image(java.lang.String url, double requestedWidth, double requestedHeight, boolean preserveRatio, boolean smooth)
  • Image(java.lang.String url, double requestedWidth, double requestedHeight, boolean preserveRatio, boolean smooth, boolean backgroundLoading)

As you can see, there are only a handful of parameters common to all of the constructors that are used in various combinations for different loading scenarios. Table 7-1 briefly describes each parameter.

Table 7-1. Common Parameters When Loading Images of the Class javafx.scene.image.Image

Parameter Data Type Description

inputStream java.io.InputStream

An input stream such as a file or network.

url String

An imagersquo;s URL location such as a file on the local filesystem or a web server hosting an image file.

backgroundLoading boolean

Loads the image in the background (off the JavaFX application thread).

requestedWidth double

Specifies an imagersquo;s bounding box width.

requestedHeight double

Specifies an imagersquo;s bounding box height.

preserveRatio boolean

To keep an imagersquo;s aspect ratio within the bounding box.

smooth boolean

A true indicates the use of a better algorithm to smooth the image, which can be slower; otherwise it will use the lower quality, which will render pixels faster.

To demonstrate loading an image, Listing 7-1 shows three ways of loading images. The code listing demonstrates loading an image from the local filesystem, classpath, and a remote host system such as a web server.

Listing 7-1. Loading Images from the Filesystem, the Classpath, and a Remote Web Server try {

// The current thread context should not be on the GUI thread.

// loading an image from a Windows file system

File file = new File('C:\\Users\\jdoe\\Pictures\\myphoto.jpg');

String localUrl = file.toURI().toURL().toString();

// don#39;t load in the background (block)

Image localImage = new Image(localUrl, false);

// loading an image from the classpath in a jar file

String urlStr = this.getClass()

.getClassLoader()

.getResource('images/myphoto.jpg')

.toExternalForm();

// load in the background (non-blocking)

Image cpUrl = new Image(urlStr, true);

// loading an image from a webserver

String remoteUrl = 'http://mycompany.com/myphoto.jpg';

// load in the background (non-blocking)

Image remoteImage = new Image(remoteUrl, true);

剩余内容已隐藏,支付完成后下载完整资料


你听过有人说“当两个世界发生碰撞”吗?当一个人来自不同的背景或文化时,他的这种表达方式就会出现在他们不一致的情况下,并且必须面对非常艰难的决定。在构建需要图形或动画的GUI应用程序时,我们经常遇到业务和游戏世界之间的冲突。换句话说,在开发应用程序时,从业务应用程序和视频游戏相似的效果中获得UI方面的良好平衡是很好的。

在不断变化的富Internet应用程序世界(RIA)中,您可能已经注意到动画的使用越来越多,比如脉冲按钮、转换、移动背景等等。GUI应用程序可以使用动画提供视觉线索,让用户知道下一步该做什么。使用JavaFX,您将能够同时拥有两个世界的优点,创建吸引人的图形以及处理业务事务的基于表单的应用程序。

在本章中,您将了解JavaFX图形的基础知识,例如显示和操作图像。另外,在本章中,您将学习高级动画api。系紧你的安全带;您将发现解决方案,将酷游戏样界面集成到日常应用程序中。

在本章中,您将了解以下内容:

bull;加载和显示图像。

bull;后台任务

bull;发展指标

bull;改变图像的颜色设置。

bull;将位映像写入磁盘。

bull;拖放图像文件。

bull;使用键值、关键帧和时间线进行动画。

bull;动画过渡类

bull;顺序和并行转换。

处理图像

JavaFX的另一个强大功能是在场景图上显示标准图像文件格式的能力。在本节中,您将学习如何加载、显示、缩放和旋转图像。作为奖励,你还将学习如何轻松地改变图像的颜色属性,比如它的色调、饱和度、亮度和对比度。

在了解了JavaFX图像和ImageView api的基础知识之后,您将了解一个照片查看器应用程序的示例。这个有趣的应用程序允许您缩放、旋转和操作图像。

卡尔·迪格,格里特·格伦沃尔德,何塞·佩内达,肖恩·菲利普斯和马克·赫克勒,2017年227年。

C. Dea等,以JavaFX 9为例,DOI 10.1007/978-1-4842-1961-4_7。

加载图片

您可能已经注意到Internet上许多标准的图像文件格式,例如.jpg、.png、.gif和.bmp。为了加载标准的图像文件格式,JavaFX提供了JavaFX .scene.image。图像的API。图像类有许多方便的构造函数,方便不同的加载策略,如下表所示:

bull;图像(io。InputStream InputStream)

bull;图像(io。输入流是,双请求宽度,双请求高度,布尔预服务器,布尔平滑)

bull;图像(. lang。字符串url)

bull;图像(. lang。字符串url,布尔backgroundLoading)

bull;图像(. lang。字符串url,双requestedWidth, double requestedHeight, boolean preserveRatio, boolean smooth)

bull;图像(. lang。字符串url,双requestedWidth, double requestedHeight, boolean preserveRatio, boolean smooth, boolean backgroundLoading)

正如您所看到的,对于不同的加载场景,在各种组合中使用的所有构造函数都只有少数几个参数。表7-1简要描述了每个参数。

Table 7-1. Common Parameters When Loading Images of the Class javafx.scene.image.Image

Parameter Data Type Description

inputStream java.io.InputStream

An input stream such as a file or network.

url String

An imagersquo;s URL location such as a file on the local filesystem or a web server hosting an image file.

backgroundLoading boolean

Loads the image in the background (off the JavaFX application thread).

requestedWidth double

Specifies an imagersquo;s bounding box width.

requestedHeight double

Specifies an imagersquo;s bounding box height.

preserveRatio boolean

To keep an imagersquo;s aspect ratio within the bounding box.

smooth boolean

A true indicates the use of a better algorithm to smooth the image, which can be slower; otherwise it will use the lower quality, which will render pixels faster.

为了演示加载图像,清单7-1显示了加载图像的三种方法。代码清单展示了从本地文件系统、类路径和远程主机系统(如web服务器)加载图像。

Listing 7-1. Loading Images from the Filesystem, the Classpath, and a Remote Web Server try {

// The current thread context should not be on the GUI thread.

// loading an image from a Windows file system

File file = new File('C:\\Users\\jdoe\\Pictures\\myphoto.jpg');

String localUrl = file.toURI().toURL().toString();

// don#39;t load in the background (block)

Image localImage = new Image(localUrl, false);

// loading an image from the classpath in a jar file

String urlStr = this.getClass()

.getClassLoader()

.getResource('images/myphoto.jpg')

.toExternalForm();

// load in the background (non-blocking)

Image cpUrl = new Image(urlStr, true);

// loading an image from a webserver

String remoteUrl = 'http://mycompany.com/myphoto.jpg';

// load in the background (non-blocking)

Image remoteImage = new Image(remoteUrl, true);

System.out.println(localUrl); // file:/C:/Users/jdoe/Pictures/myphoto.jpg

System.out.println(cpUrl); // jar:file:/myApp.jar!/images/myphoto.jpg

System.out.println(remoteUrl); // http://mycompany.com/myphoto.jpg

// ... rest of the code

} catch (MalformedURLException ex) {

ex.printStackTrace(); }

这个清单演示了如何使用构造函数接收到一个图像的URL路径和一个布尔参数来在后台线程中执行图像的加载。由于构造函数必须接受URL对象,所以必须将文件的路径转换为URL对象(URL规范)。

清单7-1首先使用一个基于字符串的文件对象从本地文件系统中加载一个图像,该文件对象的路径位置为图像。在这个场景中,我指定了一个基于Microsoft windows的绝对文件路径。在这里您将注意到在Windows操作系统上表示文件路径的字符串中的双反斜杠。第一个反斜杠是在Java字符串中摆脱反斜杠字符。toURL()方法将文件系统路径转换为标准URL格式的字符串。好的是方法调用将绝对文件路径转换为标准统一资源定位器规范的格式。字符串将包含前缀文件:表示协议和路径信息。

与本地文件系统类似,在Java类路径或资源目录上加载一个图像文件。假设应用程序是作为可执行JAR构建的,清单7-1中的示例显示了JAR:文件:在JAR存档文件中表示一个文件。特别注意使用getClassLoader()方法的代码。一些环境(如OSGi平台)将在自己的上下文(即bundle)中使用单独的类加载器。通过使用getClassLoader()方法,代码可以安全地从正确的类装入器上下文中获取资源。例如,如果一个项目有一个包含图像文件的资源目录,您可以根据类路径加载资源,如下所示:

src/

--main/

----java/

-------com/

---------mycompany/

-----------MyClass.java

----resources/

-------com/

---------mycompany/

-----------my_image.jpg

String urlStr = MyClass.class

.getClassLoader()

.getResource('com/mycompany/my_image.jpg')

.toExternalForm();

在本例中,您将注意到资源字符串com/mycompany/my_image.jpg在开始时拥有路径信息。有时,项目会将所有图像图标放置在一个名为images的目录中,或者放在包名称空间中的collocation中。

回到清单7-1中的代码,最后一个策略是一个示例,它显示了在远程web服务器上加载一个映像的能力。您可以看到代码也使用了http:作为URL路径的前缀,以演示在远程主机web服务器上加载图像。

重要的是要记住,清单7-1的代码对于使用布尔值false进行阻塞调用的语句不应该在JavaFX应用程序线程上使用。这是由于可能阻塞UI线程,从而使应用程序看起来冻结。根据图像文件或网络延迟的大小,UI开发人员(即您!)的目标是通过在后台线程上加载图像而不阻塞UI线程(JavaFX应用程序线程)。加载图像后,图像现在可以在JavaFX应用程序线程(ImageView节点)上呈现。如果您传递true的布尔值,那么ImageView节点将显示为空,直到后台线程完成加载图像对象。

现在您已经知道如何加载图像了,您将学习如何使用JavaFX ImageView来显示它们。

显示的图像

在加载一个图像对象之后,需要将它传递给一个ImageView对象,以显示在JavaFX场景图上。javafx.scene.image。ImageView节点只是一个包装器对象,它引用了前面讨论过的图像对象。因为ImageView对象是一个JavaFX节点对象,因此您将能够应用效果并执行转换。

当一个ImageView节点用于应用诸如模糊等特殊效果时,图像的像素数据实际上并不是被操纵的,而是被复制的,被计算并显示在ImageView节点上以供显示。当有许多ImageView对象都指向单个图像对象时,这是一种非常强大的技术。清单7-2将一个异步(后台加载)的图像加载到ImageView构造函

剩余内容已隐藏,支付完成后下载完整资料


资料编号:[463465],资料为PDF文档或Word文档,PDF文档可免费转换为Word

原文和译文剩余内容已隐藏,您需要先支付 30元 才能查看原文和译文全部内容!立即支付

以上是毕业论文外文翻译,课题毕业论文、任务书、文献综述、开题报告、程序设计、图纸设计等资料可联系客服协助查找。