DefaultDPI is the default dot resolution for image drawing in dots per inch.
const DefaultDPI = 96
func UseBackgroundColor(c color.Color) option
UseBackgroundColor specifies the image background color. Without UseBackgroundColor, the default color is white.
func UseDPI(dpi int) option
UseDPI sets the dots per inch of a canvas. It should only be used as an option argument when initializing a new canvas.
Canvas implements the vg.Canvas interface, drawing to an image.Image using vgimg and painting that image into a Gioui context.
type Canvas struct {
// contains filtered or unexported fields
}
▹ Example
func New(gtx layout.Context, w, h vg.Length, opts ...option) *Canvas
New returns a new image canvas with the provided dimensions and options. The currently accepted options are UseDPI and UseBackgroundColor. If the resolution or background color are not specified, defaults are used.
func (c *Canvas) DPI() float64
DPI returns the resolution of the receiver in pixels per inch.
func (c *Canvas) DrawImage(rect vg.Rectangle, img image.Image)
DrawImage draws the image, scaled to fit the destination rectangle.
func (c *Canvas) Fill(p vg.Path)
Fill fills the given path.
func (c *Canvas) FillString(fnt font.Face, pt vg.Point, txt string)
FillString fills in text at the specified location using the given font. If the font size is zero, the text is not drawn.
func (c *Canvas) Paint() *op.Ops
Paint returns the painting operations.
func (c *Canvas) Pop()
Pop restores the context saved by the corresponding call to Push().
func (c *Canvas) Push()
Push saves the current line width, the current dash pattern, the current transforms, and the current color onto a stack so that the state can later be restored by calling Pop().
func (c *Canvas) Rotate(rad float64)
Rotate applies a rotation transform to the context. The parameter is specified in radians.
func (c *Canvas) Scale(x, y float64)
Scale applies a scaling transform to the context.
func (c *Canvas) Screenshot() (image.Image, error)
Screenshot returns a screenshot of the canvas as an image.
func (c *Canvas) SetColor(clr color.Color)
SetColor sets the current drawing color. Note that fill color and stroke color are the same, so if you want different fill and stroke colors then you must set a color, draw fills, set a new color and then draw lines.
The initial color is black. If SetColor is called with a nil color then black is used.
func (c *Canvas) SetLineDash(pattern []vg.Length, offset vg.Length)
SetLineDash sets the dash pattern for lines. The pattern slice specifies the lengths of alternating dashes and gaps, and the offset specifies the distance into the dash pattern to start the dash.
The initial dash pattern is a solid line.
func (c *Canvas) SetLineWidth(w vg.Length)
SetLineWidth sets the width of stroked paths. If the width is not positive then stroked lines are not drawn.
The initial line width is 1 point.
func (c *Canvas) Size() (w, h vg.Length)
Size implement vg.CanvasSizer.
func (c *Canvas) Stroke(p vg.Path)
Stroke strokes the given path.
func (c *Canvas) Translate(pt vg.Point)
Translate applies a translational transform to the context.