2015-06-20 55 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 []