2015-06-20 56 views
1

我正在使用wxHaskell在窗口中顯示完整圖像。我的代碼是:用wxHaskell顯示完整圖像

import Graphics.UI.WX 
import Graphics.UI.WXCore 

main :: IO() 
main = start testimg 

testimg :: IO() 
testimg = do 
    f <- frame [text := "Test Image"] 
    p <- panel f [] 

    image <- bitmapCreateFromFile "landscape.png" 
    imagep <- panel p [ on paint := onPaint image ] 

    set f [ layout:= fill $ container p $ widget imagep ] 

    where 
    onPaint image dc rect = drawBitmap dc image pointZero True [] 

無論如何,當應用程序運行什麼都沒有顯示(甚至沒有窗口的邊界)。我怎樣才能使它工作?

回答

2

您錯過了之前的widget imagep,其結果是您在畫面中繪製的面板沒有任何表面。我也建議設置一個outerSize。你可能也想看看https://github.com/wxHaskell/wxHaskell/blob/master/samples/wx/ImageViewer.hs的靈感。祝你好運!

import Graphics.UI.WX 
import Graphics.UI.WXCore 

main :: IO() 
main = start testimg 

testimg :: IO() 
testimg = do 
    f <- frame [text := "Test Image"] 
    p <- panel f [] 

    image <- bitmapCreateFromFile "landscape.png" 
    imagep <- panel p [ on paint := onPaint image ] 

    set f [ layout:= fill $ container p $ fill $ widget imagep 
     , outerSize := sz 500 500 
     ] 

    where 
    onPaint image dc rect = drawBitmap dc image pointZero True []