gpt4 book ai didi

forms - windows.forms 和重绘位图

转载 作者:行者123 更新时间:2023-12-04 01:06:14 26 4
gpt4 key购买 nike

我正在实现一个 gameboy 模拟器,就像我之前的许多人一样。

我正在尝试实现 PPU 并为此使用代表屏幕的类。

// needed because VS can't find it as dependency
#r "nuget: System.Windows.Forms"
open System
open System.Windows.Forms
open System.Drawing

type Screen(title, width : int, height : int) as screen =
inherit Form()

let mutable canvas = new Bitmap(width, height)

do
// set some attributes of the screen
screen.Size <- new Size(width, height)
screen.Text <- title

interface IDisposable with
member S.Dispose() = (canvas :> IDisposable).Dispose()

override S.OnPaint e =
e.Graphics.DrawImage(canvas,0,0) // here
base.OnPaint(e)

member S.Item
with get (w, h) = canvas.GetPixel(w,h)
and set (w,h) pixel = canvas.SetPixel(w,h,pixel)

但是在重绘位图后我无法让它更新屏幕,它不显示重绘的图像。

重绘

let main () =
let screen = new Screen("gameboy",800,600)
Application.Run(screen)
// test example
for i in 0 .. 300 do
screen.[i,i] <- Drawing.Color.Black
(screen :> Form).Refresh()

即如何让它在位图更新后重绘?

最佳答案

Application.Run 被调用后,您不能做任何图形化的事情,因为直到用户关闭主窗体它才会完成。相反,您可以创建一个在主窗体加载后调用的事件处理程序,如下所示:

let main argv =
let screen = new Screen("gameboy",800,600)
screen.Load.Add(fun _ ->
for i in 0 .. 300 do
screen.[i,i] <- Drawing.Color.Black)
Application.Run(screen)
0

关于forms - windows.forms 和重绘位图,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/66325086/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com