-
-
Notifications
You must be signed in to change notification settings - Fork 103
Images
Taco de Wolff edited this page Nov 16, 2022
·
2 revisions
Images can be rendered to a canvas at a certain resolution specifying the pixels per millimeter. A larger resolution will thus result in smaller images.
// Load the image data
lenna, err := os.Open("lenna.png")
if err != nil {
panic(err)
}
// Decode the PNG image data to an image.Image
img, err := png.Decode(lenna)
if err != nil {
panic(err)
}
// Draw the image at coordinates (10,10) with a resolution of 30 px/mm
c.DrawImage(10, 10, img, canvas.DPMM(30.0))
For some renderers the original image data is required (such as for SVG), in which case it is inefficient to decode the image and then re-encode it in the renderer. For this reason you can load images instead using:
// Load the image data
lenna, err := os.Open("lenna.png")
if err != nil {
panic(err)
}
// Create a new image object
img, err := canvas.NewPNGImage(lenna)
if err != nil {
panic(err)
}
// Draw the image at coordinates (10,10) with a resolution of 30 px/mm
c.DrawImage(10, 10, img, canvas.DPMM(30.0))