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
+10.5k Golang : Generate 403 Forbidden to protect a page or prevent indexing by search engine
+13.7k Golang : Check if an integer is negative or positive
+14.8k Golang : Normalize unicode strings for comparison purpose
+16.3k Golang : Find out mime type from bytes in buffer
+6.3k Javascript : Generate random key with specific length
+8.8k Golang : Gorilla web tool kit schema example
+27.2k Golang : Find files by name - cross platform example
+10.3k Golang : Detect number of faces or vehicles in a photo
+30.5k Golang : Generate random string
+5.1k Golang : Check if a word is countable or not
+13.6k Golang : Set image canvas or background to transparent