【问题标题】:Display a full image with wxHaskell使用 wxHaskell 显示完整图像
【发布时间】:2015-06-20 20:43:21
【问题描述】:

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

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

【问题讨论】:

    标签: haskell wxhaskell


    【解决方案1】:

    您在widget imagep 之前错过了fill,效果是您在图片中绘制的面板没有任何表面。我也建议设置一个 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 []
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2014-03-23
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2015-11-30
      • 2016-04-21
      • 2018-07-03
      • 1970-01-01
      相关资源
      最近更新 更多