You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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 datalenna, err:=os.Open("lenna.png")
iferr!=nil {
panic(err)
}
// Decode the PNG image data to an image.Imageimg, err:=png.Decode(lenna)
iferr!=nil {
panic(err)
}
// Draw the image at coordinates (10,10) with a resolution of 30 px/mmc.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 datalenna, err:=os.Open("lenna.png")
iferr!=nil {
panic(err)
}
// Create a new image objectimg, err:=canvas.NewPNGImage(lenna)
iferr!=nil {
panic(err)
}
// Draw the image at coordinates (10,10) with a resolution of 30 px/mmc.DrawImage(10, 10, img, canvas.DPMM(30.0))