go - Convert returned values to a specific type -


i'm getting started go , i've come across following "problem".

i'm using function returns 4 unsigned 32 bit integers, , wondering best method convert these values 8 bit integers when i'm assigning them. (or if possible). have got work assigning them uint32, converting them after wondering if there more concise way of doing it.

example:

r, g, b, _ := image.at(x, y).rgba() // ideally convert them @ stage 

so image.at returns uint32, r,g,b uint8

thanks

go has no syntax want there. you're best bet in next line down.

rbig, gbig, bbig := image.at(x, y).rgba() r, g, b := uint8(rbig), uint8(gbig), uint8(bbig) 

if annoys though make helper function

func convert(i, j, k, _ uint32) (uint8, uint8, uint8) { return uint8(i), uint8(j), uint8(k) } r, g, b := convert(image.at(x, y).rgba()) 

still minimum of 2 lines can reuse function anywhere need , call site might little cleaner you.


Comments

Popular posts from this blog

jquery - How can I dynamically add a browser tab? -

node.js - Getting the socket id,user id pair of a logged in user(s) -

keyboard - C++ GetAsyncKeyState alternative -