Love2dCS icon indicating copy to clipboard operation
Love2dCS copied to clipboard

Convert Image to Canvas?

Open Shadowblitz16 opened this issue 5 years ago • 7 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)?

Shadowblitz16 avatar Jun 04 '19 16:06 Shadowblitz16

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

endlesstravel avatar Jun 05 '19 01:06 endlesstravel

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

Shadowblitz16 avatar Jun 05 '19 20:06 Shadowblitz16

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

Shylie avatar Jul 02 '19 13:07 Shylie

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

Shadowblitz16 avatar Aug 17 '19 04:08 Shadowblitz16

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);
}

endlesstravel avatar Sep 06 '19 02:09 endlesstravel

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

Shadowblitz16 avatar Sep 06 '19 02:09 Shadowblitz16

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

endlesstravel avatar Jan 28 '20 09:01 endlesstravel