Skip to content

Render Canvas to an arbitrarily-sized image #4535

Description

@johnzhou721

What is the problem or limitation you are having?

I am building an app in which a preview of a document is displayed onscreen that is drawn using Canvas; however, I needed the ability to export that preview onto an arbitrarily-sized image.

Describe the solution you'd like

A size parameter on as_image of Canvas that lets you export a scaled view of the Canvas.

This will be implemented in most backends by scaling the Canvas before rendering onto an image; reset_transform must be handled appropriately. Cocoa and iOS allows for setting a different logical size for an image than the physical size, which can be useful to implement this

Describe alternatives you've considered

  1. Status quo. One must manually resize the canvas, wait for layout, and then grab the image, and then reset image.
  2. An canvas-like API on toga.Image that allows directly annotating an image.

Additional context

A desktop implementation (with some additional fixes) without reset_transform support lives in johnzhou721/togax-frost, my personal component library. It has been used in johnzhou721/tiler successfully.

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew features, or improvements to existing features.

    Projects

    Status
    Ready

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions