MCPcopy Create free account
hub / github.com/cogentcore/core / SetImage

Method SetImage

svg/image.go:66–95  ·  view source on GitHub ↗

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)

Source from the content-addressed store, hash-verified

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.
66func (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
97func (g *Image) DrawImage(sv *SVG) {
98 if g.Pixels == nil {

Callers 5

OpenImageMethod · 0.95
UnmarshalXMLMethod · 0.95
handleElementFunction · 0.45
GrabEyeImgMethod · 0.45
ViewDepthMethod · 0.45

Calls 7

SetImageSizeMethod · 0.95
Vector2FromPointFunction · 0.92
Scale2DFunction · 0.92
SizeMethod · 0.65
DrawMethod · 0.65
BoundsMethod · 0.45
TransformMethod · 0.45

Tested by

no test coverage detected