Golang image.NRGBA and NRGBA64 types examples
package image
NRGBA is an in-memory image whose At method returns color.NRGBA values.
NRGBA64 is an in-memory image whose At method returns color.NRGBA64 values.
Golang image.NRGBA and NRGBA64 types usage examples
Example 1: (taken https://github.com/disintegration/imaging/blob/master/tools.go )
// Crop cuts out a rectangular region with the specified bounds
// from the image and returns the cropped image.
func Crop(img image.Image, rect image.Rectangle) *image.NRGBA {
src := toNRGBA(img)
srcRect := rect.Sub(img.Bounds().Min)
sub := src.SubImage(srcRect)
return Clone(sub) // New image Bounds().Min point will be (0, 0)
}
Example 2:
func getSubImage(src image.Image, rect image.Rectangle) image.Image {
if img, ok := src.(*image.NRGBA); ok {
return img.SubImage(rect)
}
if img, ok := src.(*image.NRGBA64); ok {
return img.SubImage(rect)
}
...
References :
https://github.com/disintegration/imaging/blob/master/tools.go
Advertisement
Something interesting
Tutorials
+12.7k Golang : zlib compress file example
+6.3k Golang : Calculate US Dollar Index (DXY)
+9.7k Golang : Populate slice with sequential integers example
+11.2k Golang : How to pipe input data to executing child process?
+5.2k Golang : PGX CopyFrom to insert rows into Postgres database
+6.3k Golang : Extract sub-strings
+9k Golang : Build and compile multiple source files
+11.4k Golang : Delay or limit HTTP requests example
+11.6k SSL : The certificate is not trusted because no issuer chain was provided
+11k How to test Facebook App on localhost ?
+9.3k Golang : How to get ECDSA curve and parameters data?