2017-11-28 15:42
浏览 322

将图像从* image.YCbCr转换为* image.RGBA

I am loading a jpeg from the disk, and I would like to do some RGBA operations on it.

However, since the jpeg is not RGBA, i get an error when I try to use it as such:

return thumbnail.(*image.RGBA)

yeileds the error:

interface conversion: image.Image is *image.YCbCr, not *image.RGBA

Is there an easy way to convert the image to RGBA once I have loaded it in memory? (Other operations are in RGBA later on, so that is the color model I want to use in memory).

图片转代码服务由CSDN问答提供 功能建议



  thumbnail,err:= jpeg 解码(imageAsReader)
返回缩略图。(* image.RGBA)

出现错误: < pre> 接口转换:image.Image是* image.YCbCr,而不是* image.RGBA

是否有一种简单的方法可以将图像转换为RGBA 一旦我将其加载到内存中? (其他操作稍后将在RGBA中进行,所以这是我要在内存中使用的颜色模型。)

  • 写回答
  • 关注问题
  • 收藏
  • 邀请回答

1条回答 默认 最新

  • dongxu198714 2017-11-28 19:44

    As the comments suggest, you have to create a new image and draw into it: b := thumbnail.Bounds() m := image.NewRGBA(image.Rect(0, 0, b.Dx(), b.Dy())) draw.Draw(m, m.Bounds(), thumbnail, b.Min, draw.Src)

    YCbCr is a sub-sampled image, so it doesn't map directly to the 4-bytes-per-pixel of RGBA.

    打赏 评论

相关推荐 更多相似问题