我正在使用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 []
无论如何,当应用程序运行时,不会显示任何内容(甚至不显示窗口的边框)。我怎样才能使它发挥作用?
答案 0 :(得分:2)
你在fill
之前错过了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 []