1

我正在使用 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 []

无论如何,当应用程序运行时,什么都不会显示(甚至窗口的边框也不显示)。我怎样才能让它工作?

4

1 回答 1

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 []
于 2015-11-13T23:24:42.373 回答