@Override
public
Image getImage(Object element)
{
//
得到文件图标
ImageIcon systemIcon = (ImageIcon) FileSystemView.getFileSystemView().getSystemIcon((File) element);
java.awt.Image image = systemIcon.getImage();
int
width = image.getWidth(
null
);
int
height = image.getHeight(
null
);
//
创建用于绘制
Icon
的缓冲区
BufferedImage bufferedImage =
new
BufferedImage(width, height, BufferedImage.
TYPE_INT_RGB
);
//
绘制
Icon
到缓冲区
Graphics2D g2d = bufferedImage.createGraphics();
g2d.drawImage(image, 0, 0,
null
);
g2d.dispose();
//
读取缓冲区图片数据到一个数组
int
[] data = ((DataBufferInt) bufferedImage.getData().getDataBuffer()).getData();
//
根据数组数据生成
ImageData
对象
ImageData imageData =
new
ImageData(width, height, 24,
new
PaletteData(0xFF0000, 0x00FF00, 0x0000FF));
imageData.setPixels(0, 0, data.
length
, data, 0);
//
生成
Image
对象
Image swtImage =
new
Image(PlatformUI.getWorkbench().getDisplay(), imageData);
return
swtImage;
}
|
@Override
public
Image getImage(Object element)
{
//
得到文件图标
ImageIcon systemIcon = (ImageIcon) FileSystemView.getFileSystemView().getSystemIcon((File) element);
java.awt.Image image = systemIcon.getImage();
int
width = image.getWidth(
null
);
int
height = image.getHeight(
null
);
//
创建用于绘制
Icon
的缓冲区
BufferedImage bufferedImage =
new
BufferedImage(width, height, BufferedImage.
TYPE_INT_RGB
);
//
绘制
Icon
到缓冲区
Graphics2D g2d = bufferedImage.createGraphics();
g2d.drawImage(image, 0, 0,
null
);
g2d.dispose();
//
读取缓冲区图片数据到一个数组
int
[] data = ((DataBufferInt) bufferedImage.getData().getDataBuffer()).getData();
//
将没有颜色的点设置为白色
for
(
int
i = 0; i < data.
length
; i++)
{
if
(data[i] == 0)
data[i] = 0xFFFFFF;
}
//
根据数组数据生成
ImageData
对象
ImageData imageData =
new
ImageData(width, height, 24,
new
PaletteData(0xFF0000, 0x00FF00, 0x0000FF));
imageData.setPixels(0, 0, data.
length
, data, 0);
//
生成
Image
对象
Image swtImage =
new
Image(PlatformUI.getWorkbench().getDisplay(), imageData);
return
swtImage;
}
|
@Override
public
Image getImage(Object element)
{
//
得到文件图标
ImageIcon systemIcon = (ImageIcon) FileSystemView.getFileSystemView().getSystemIcon((File) element);
java.awt.Image image = systemIcon.getImage();
int
width = image.getWidth(
null
);
int
height = image.getHeight(
null
);
//
得到
Icon
的数据缓冲区
BufferedImage bufferedImage = (BufferedImage) systemIcon.getImage();
//
读取缓冲区图片数据到一个数组
int
[] data = ((DataBufferInt) bufferedImage.getData().getDataBuffer()).getData();
//
将没有颜色的点设置为白色
for
(
int
i = 0; i < data.
length
; i++)
{
if
(data[i] == 0)
data[i] = 0xFFFFFF;
}
//
根据数组数据生成
ImageData
对象
ImageData imageData =
new
ImageData(width, height, 24,
new
PaletteData(0xFF0000, 0x00FF00, 0x0000FF));
imageData.setPixels(0, 0, data.
length
, data, 0);
//
生成
Image
对象
Image swtImage =
new
Image(PlatformUI.getWorkbench().getDisplay(), imageData);
return
swtImage;
}
|