关于Eclipse 的Image 和dispose 方法

Eclispe Image 类的Java 文档
public final class Image extends Resource implements Drawable

Instances of this class are graphics which have been prepared for display on a specific device.

这个类表示一个图像,该图像可以展示在一个设备上。(设备:Display 就是一个设备)

That is, they are ready to paint using methods such as GC.drawImage() and display on widgets with, for example, Button.setImage() .

可以通过GC.drawImage() 和小部件来显示。(如:Button.setImage())

If loaded from a file format that supports it, an Image may have transparency, meaning that certain pixels are specified as being transparent when drawn. Examples of file formats that support transparency are GIF and PNG.

(不太理解) 当从一个支持的文件格式加载图像,这个图像也许会有透明度,这意味着当画这个图像时,可能特定的像素会是透明的。支持透明度的格式有GIF and PNG。


There are two primary ways to use Images .

创造一个Image 有两种方式:

The first is to load a graphic file from disk and create an Image from it. This is done using an Image constructor, for example:

第一种方式是从磁盘上加载文件,并从根据文件创建Image.

    Image i = new Image(device, "C://graphic.bmp");
 

A graphic file may contain a color table specifying which colors the image was intended to possess. In the above example, these colors will be mapped to the closest available color in SWT. It is possible to get more control over the mapping of colors as the image is being created, using code of the form:

一个图像可能包含一个颜色表,如果你需要这个表,可以通过下面的方式获得:

    ImageData data = new ImageData("C://graphic.bmp"); 
    RGB[] rgbs = data.getRGBs(); 
    // At this point, rgbs contains specifications of all
    // the colors contained within this image. You may
    // allocate as many of these colors as you wish by
    // using the Color constructor Color(RGB), then
    // create the image:
    Image i = new Image(device, data);
 

Applications which require even greater control over the image loading process should use the support provided in class ImageLoader .

如果你的应用对图像加载有更高的控制需要,可以通过ImageLoader 来实现。


Application code must explicitly invoke the Image.dispose() method to release the operating system resources managed by each instance when those instances are no longer required.

Image.dispose() 方法必须比精确调用。当Image 实例不再被使用时,使用Image.dispose() 释放被这个Image 实例管理的操作系统资源。


关于在Eclipse 中处理系统资源的方法可以参见:

1   Eclipse中的图片资源管理

2   Using Images in the Eclipse UI

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值