On Thu, Feb 14, 2013 at 8:40 PM, Philipp Schumann
<
philipp....@gmail.com> wrote:
> Would anyone know of a smarter/better/shorter way? As an aside, wouldn't an
> image.Image.Clone() method be useful in the standard library?
When I want to work on a clone, I usually convert to RGBA at the same time:
func CloneToRGBA(src image.Image) draw.Image {
b := src.Bounds()
dst := image.NewRGBA(b)
draw.Draw(dst, b, src, b.Min, draw.Src)
return dst
}
If you must keep the original image type, a type switch is the way to
go. I would write it like
http://play.golang.org/p/R7VPM30BBG
P.S. you'll also need to switch on image.YCbCr if you want to clone
the result of decoding JPEGs.