final
Image image
=
new
Image(display,
getClass(),getResourceAsStream( " Idea.jpg " ));
final int width = image.getBounds().width;
final int height = image.getBounds().height;
final Image scaled050 = new Image(display,
image.getImageData().scaledTo(( int )(width * 0.5 ),( int )(height * 0.5 )));
final Image scaled200 = new Image(display,
image.getImageData().scaledTo(( int )(width * 2 ),( int )(height * 2 )));
final Image scaledGC200 = new Image(display,( int )(width * 2 ),( int )(height * 2 ));
GC gc = new GC(scaledGC200);
gc.drawImage(image, 0 , 0 ,width,height, 0 , 0 ,width * 2 ,height * 2 );
gc.dispose();
canvas.addPaintListener( new PaintListener() {
public void paintControl(PaintEvent e) {
e.gc.drawImage(image, 0 , 0 ,width,height, 0 , 0 ,( int )(width * 0.5 ),( int )(height * 0.5 ));
e.gc.drawImage(scaled050, 100 , 0 );
e.gc.drawImage(scaledGC200, 0 , 75 );
e.gc.drawImage(scaled200, 225 , 175 );
}
});
getClass(),getResourceAsStream( " Idea.jpg " ));
final int width = image.getBounds().width;
final int height = image.getBounds().height;
final Image scaled050 = new Image(display,
image.getImageData().scaledTo(( int )(width * 0.5 ),( int )(height * 0.5 )));
final Image scaled200 = new Image(display,
image.getImageData().scaledTo(( int )(width * 2 ),( int )(height * 2 )));
final Image scaledGC200 = new Image(display,( int )(width * 2 ),( int )(height * 2 ));
GC gc = new GC(scaledGC200);
gc.drawImage(image, 0 , 0 ,width,height, 0 , 0 ,width * 2 ,height * 2 );
gc.dispose();
canvas.addPaintListener( new PaintListener() {
public void paintControl(PaintEvent e) {
e.gc.drawImage(image, 0 , 0 ,width,height, 0 , 0 ,( int )(width * 0.5 ),( int )(height * 0.5 ));
e.gc.drawImage(scaled050, 100 , 0 );
e.gc.drawImage(scaledGC200, 0 , 75 );
e.gc.drawImage(scaled200, 225 , 175 );
}
});
其他和图片有关的的处理参见:http://www.eclipse.org/articles/Article-SWT-images/graphics-resources.html