NewImage creates a new image plotter. Image will plot img inside the rectangle defined by the (xmin, ymin) and (xmax, ymax) points given in the data space. The img will be scaled to fit inside the rectangle.
(img image.Image, xmin, ymin, xmax, ymax float64)
| 27 | // (xmin, ymin) and (xmax, ymax) points given in the data space. |
| 28 | // The img will be scaled to fit inside the rectangle. |
| 29 | func NewImage(img image.Image, xmin, ymin, xmax, ymax float64) *Image { |
| 30 | if src, ok := img.(*image.Uniform); ok { |
| 31 | img = uniform{ |
| 32 | src, |
| 33 | image.Rect(0, 0, int(xmax-xmin+0.5), int(ymax-ymin+0.5)), |
| 34 | } |
| 35 | } |
| 36 | bounds := img.Bounds() |
| 37 | cols := bounds.Dx() |
| 38 | rows := bounds.Dy() |
| 39 | dx := math.Abs(xmax-xmin) / float64(cols) |
| 40 | dy := math.Abs(ymax-ymin) / float64(rows) |
| 41 | return &Image{ |
| 42 | img: img, |
| 43 | cols: cols, |
| 44 | rows: rows, |
| 45 | xmin: xmin, |
| 46 | xmax: xmax, |
| 47 | dx: dx, |
| 48 | ymin: ymin, |
| 49 | ymax: ymax, |
| 50 | dy: dy, |
| 51 | } |
| 52 | } |
| 53 | |
| 54 | // Plot implements the Plot method of the plot.Plotter interface. |
| 55 | func (img *Image) Plot(c draw.Canvas, p *plot.Plot) { |