endlesstravel / Love2dCS

C# Wrapper for LÖVE, a 2d game engine

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Convert Image to Canvas?

Shadowblitz16 opened this issue · comments

Is it possible to convert a image to a canvas and back so I can draw onto it?
if not could you add Graphics.NewCanvas(Image Image) and Graphics.NewCanvas(ImageData ImageData)?

commented

There is no such method, but you can draw an image onto the canvas.

but this requires the draw event right?
I was trying to do it so it could be used anywhere

See Love.Graphics.Present. This should be what you are looking for if you need to draw outside of the draw event.

can support be added so that images and canvases can be explicitly converted back and forth?

commented

a example here :

  1. copy the utils class into your project:
    https://gist.github.com/endlesstravel/027799eb772d644b0d4110284256da6a

  2. use it like :

static public void Test_Issue75_ToPintImage()
{
    ISSUE_75.Init();
    var imgData = ISSUE_75.PrintImage(300, 300, () =>
    {
        Graphics.SetColor(Color.LightPink);
        Graphics.Rectangle(DrawMode.Fill, 0, 0, 100, 100);
        Graphics.SetColor(Color.White);
        Graphics.Circle(DrawMode.Line, 100, 100, 20);
    });
    Resource.EncodeToFile("test.png", imgData, ImageFormat.PNG);
}

ok thankyou.
but can this be added to love2dcs as a explicit image conversion?

commented

I think i will add Resources.ToImageData to Resources class. which in #96