SetImage sets an image for the bitmap, and resizes to the size of the image or the specified size -- pass 0 for width and/or height to use the actual image size for that dimension. Copies from given image into internal image for this bitmap.
(img image.Image, width, height float32)
| 64 | // or the specified size -- pass 0 for width and/or height to use the actual image size |
| 65 | // for that dimension. Copies from given image into internal image for this bitmap. |
| 66 | func (g *Image) SetImage(img image.Image, width, height float32) { |
| 67 | sz := img.Bounds().Size() |
| 68 | if width <= 0 && height <= 0 { |
| 69 | g.SetImageSize(sz) |
| 70 | draw.Draw(g.Pixels, g.Pixels.Bounds(), img, image.Point{}, draw.Src) |
| 71 | if g.Size.X == 0 && g.Size.Y == 0 { |
| 72 | g.Size = math32.Vector2FromPoint(sz) |
| 73 | } |
| 74 | } else { |
| 75 | tsz := sz |
| 76 | transformer := draw.BiLinear |
| 77 | scx := float32(1) |
| 78 | scy := float32(1) |
| 79 | if width > 0 { |
| 80 | scx = width / float32(sz.X) |
| 81 | tsz.X = int(width) |
| 82 | } |
| 83 | if height > 0 { |
| 84 | scy = height / float32(sz.Y) |
| 85 | tsz.Y = int(height) |
| 86 | } |
| 87 | g.SetImageSize(tsz) |
| 88 | m := math32.Scale2D(scx, scy) |
| 89 | s2d := f64.Aff3{float64(m.XX), float64(m.XY), float64(m.X0), float64(m.YX), float64(m.YY), float64(m.Y0)} |
| 90 | transformer.Transform(g.Pixels, s2d, img, img.Bounds(), draw.Over, nil) |
| 91 | if g.Size.X == 0 && g.Size.Y == 0 { |
| 92 | g.Size = math32.Vector2FromPoint(tsz) |
| 93 | } |
| 94 | } |
| 95 | } |
| 96 | |
| 97 | func (g *Image) DrawImage(sv *SVG) { |
| 98 | if g.Pixels == nil { |
no test coverage detected