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
+20.3k Swift : Convert (cast) Int to int32 or Uint32
+28.8k Golang : Detect (OS) Operating System
+11.1k Golang : Read until certain character to break for loop
+13.5k Golang : How to get year, month and day?
+11k Golang : Generate random elements without repetition or duplicate
+20.2k Golang : Compare floating-point numbers
+10k Golang : Setting variable value with ldflags
+17.6k Golang : Parse date string and convert to dd-mm-yyyy format
+18.6k Golang : Get download file size
+15.6k Golang : ROT47 (Caesar cipher by 47 characters) example
+25.7k Golang : missing Mercurial command