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
+7.2k Golang : Dealing with postal or zip code example
+8.2k Golang : Add build version and other information in executables
+11.3k Golang : How to flush a channel before the end of program?
+30.5k Golang : Generate random string
+12.4k Elastic Search : Return all records (higher than default 10)
+6.5k PHP : Shuffle to display different content or advertisement
+8.6k Golang : Progress bar with ∎ character
+13.5k Golang : How to get year, month and day?
+20.2k Golang : How to get own program name during runtime ?
+13.2k Golang : How to calculate the distance between two coordinates using Haversine formula
+8.1k Golang : Check from web if Go application is running or not
+11.2k Golang : Fix - does not implement sort.Interface (missing Len method)