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
+5.9k Golang : Output or print out JSON stream/encoded data
+10.6k Golang : Surveillance with web camera and OpenCV
+14.5k Golang : Get checkbox or extract multipart form data value example
+29.7k Golang : How to convert(cast) string to IP address?
+13.6k Golang : Rename directory
+12.8k Golang : How to determine if a year is leap year?
+13.9k Golang : Accurate and reliable decimal calculations
+10.6k SSL : The certificate is not trusted because no issuer chain was provided
+10.1k Golang : How to determine a prime number?
+8k Golang : Capture text return from exec function example
+4.7k Golang : Display advertisement images or strings on random order
+13.1k Elastic Search : Mapping date format and sort by date