Added in-memory alternative to PNG renderer
This commit is contained in:
parent
c1468e8ae4
commit
d8cf23c038
1 changed files with 26 additions and 0 deletions
|
@ -23,6 +23,20 @@ func PNG(width, height int) (Renderer, error) {
|
|||
return nil, err
|
||||
}
|
||||
|
||||
func InMemory(width, height int) (Renderer, error) {
|
||||
i := image.NewRGBA(image.Rect(0, 0, width, height))
|
||||
gc, err := drawing.NewRasterGraphicContext(i)
|
||||
if err == nil {
|
||||
return &memRenderer{
|
||||
rasterRenderer{
|
||||
i: i,
|
||||
gc: gc,
|
||||
},
|
||||
}, nil
|
||||
}
|
||||
return nil, err
|
||||
}
|
||||
|
||||
// rasterRenderer renders chart commands to a bitmap.
|
||||
type rasterRenderer struct {
|
||||
i *image.RGBA
|
||||
|
@ -228,3 +242,15 @@ func (rr *rasterRenderer) Save(w io.Writer) error {
|
|||
}
|
||||
return png.Encode(w, rr.i)
|
||||
}
|
||||
|
||||
type memRenderer struct {
|
||||
rasterRenderer
|
||||
}
|
||||
|
||||
func (m *memRenderer) Save(w io.Writer) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
func (m *memRenderer) AsImage() image.Image {
|
||||
return m.i
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue