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
+8.4k Golang : Ackermann function example
+28.8k Golang : Detect (OS) Operating System
+16k Golang : How to reverse elements order in map ?
+22.6k Generate checksum for a file in Go
+6.7k Golang : Check if password length meet the requirement
+6.8k Swift : substringWithRange() function example
+12.9k Golang : Convert IPv4 address to packed 32-bit binary format
+11.3k Golang : Post data with url.Values{}
+11.5k Golang : Handle API query by curl with Gorilla Queries example
+7.4k Linux : How to fix Brother HL-1110 printing blank page problem
+13.4k Golang : Verify token from Google Authenticator App
+13.4k Golang : Get constant name from value