2011-05-31 13 views
7

Bir cc Resmi çizmek çalışıyorum ama hiçbir şey göründüğü: Resim varolduğunu test ettikSwt resmi nasıl çizilir?

Display display = new Display(); 
Shell shell = new Shell(display); 
shell.open(); 

Image image = new Image(display, "C:/sample_image.png"); 
Rectangle bounds = image.getBounds(); 

GC gc = new GC(image); 
gc.drawImage(image, 100, 100); 
// gc.drawLine(0, 0, bounds.width, bounds.height); 
// gc.drawLine(0, bounds.height, bounds.width, 0); 
// gc.dispose(); 
// image.dispose(); 

while (!shell.isDisposed()) { 
    if (!display.readAndDispatch()) 
    display.sleep(); 
} 
display.dispose(); 

ve içeriğe sahiptir - herhangi bir fikir?

+0

Bu resmi nerede çizeceksiniz? –

+0

Ekranımda. Kabuk açılır ama boş. – u123

+0

olası bir kopyası [java ile görüntüyü nasıl gösterebilirim?] (Http://stackoverflow.com/questions/4447455/how-to-show-up-an-image-with-swt-in-java) – McDowell

cevap

8

Bir Etiket oluşturun ve resmi ayarlayın.

Image myImage = new Image(display, "C:/sample_image.png"); 
Label myLabel = new Label(shell, SWT.NONE); 
myLabel.setImage(myImage); 

Bu sizin için yeterli olabilir.

3

Genellikle bir resim çekmek için Tuval kullanılır.

// Create a canvas 
Canvas canvas = new Canvas(shell, SWT.NONE); 
final Image image = new Image(display, "C:/sample_image.png"); 

// Create a paint handler for the canvas  
canvas.addPaintListener(new PaintListener() { 
    public void paintControl(PaintEvent e) { 
    e.gc.drawImage(image, 0, 0);   
    } 
}); 

SWT Resimler hakkında daha fazla bilgi için bkz. this link.