Created
September 6, 2019 02:23
-
-
Save endlesstravel/027799eb772d644b0d4110284256da6a to your computer and use it in GitHub Desktop.
love2dcs print image
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System; | |
using System.Collections.Generic; | |
using System.Linq; | |
using System.Text; | |
using System.Threading.Tasks; | |
using Love; | |
using Love.Misc; | |
class ISSUE_75 | |
{ | |
class NoSce : Scene | |
{ | |
public int w, h; | |
public Action drawAction = null; | |
public ImageData imageData; | |
public override void Draw() | |
{ | |
var canvas = Graphics.NewCanvas(w, h, new Graphics.Settings | |
{ | |
readable = true, | |
format = PixelFormat.RGBA8 | |
}); | |
Graphics.SetCanvas(canvas); | |
drawAction?.Invoke(); | |
Graphics.SetCanvas(); | |
imageData = canvas.NewImageData(); | |
canvas.Dispose(); | |
canvas = null; | |
} | |
public override bool Quit() | |
{ | |
return false; | |
} | |
public ImageData PrintImage(int w, int h, Action drawAction) | |
{ | |
this.w = w; | |
this.h = h; | |
this.drawAction = drawAction; | |
if (Graphics.IsActive()) | |
{ | |
Boot.SystemStep(this); | |
var c = Graphics.GetBackgroundColor(); | |
Graphics.Clear(c.r, c.g, c.b, c.a); | |
Graphics.Origin(); | |
this.Draw(); | |
Graphics.Present(); | |
} | |
return this.imageData; | |
} | |
} | |
static NoSce ns; | |
static public void Init() | |
{ | |
Boot.Init(new BootConfig | |
{ | |
WindowResizable = false, | |
WindowBorderless = true, | |
WindowWidth = 1, | |
WindowHeight = 1, | |
WindowX = 0, | |
WindowY = 0, | |
}); | |
ns = new NoSce(); | |
} | |
static public ImageData PrintImage(int w, int h, Action drawAction) => ns.PrintImage(w, h, drawAction); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment