image - 添加 Alpha 通道性能
问题描述
我正在寻找将我的数组转换为 PNG 图像。它目前是 RGB8 编码的图像。我可以使用以下代码执行此操作:
s2 := make([]uint8, 2048*2448*3)
err = dset.Read(&s2)
if err != nil {
panic(err)
}
var (
width = 2048
height = 2448
rgb = 3
)
to1D := func(x, y int) int {
return (x * height * rgb) + (rgb * y)
}
img := image.NewRGBA(image.Rect(0, 0, width, height))
for ix := 0; ix < width; ix++ {
for iy := 0; iy < height; iy++ {
cords := to1D(ix, iy)
img.SetRGBA(ix, iy, color.RGBA{R: s2[cords], G: s2[cords+1], B: s2[cords+2], A: 255})
}
}
有没有更好的方法来添加不涉及循环遍历每个像素并单独设置它的 Alpha 通道?
谢谢!
解决方案
推荐阅读
- php - php 脚本无法使用 SSL 连接到 MySQL
- java - 将我的程序中的值更改为数组
- javascript - 映射可迭代道具对象的问题
- mysql - 在连接语句中使用另一个表的列的值作为表的名称
- amazon-web-services - (ResourceNotFoundException) 调用PutRecord操作时:账号xxxxxxx下的Stream request-data-debugger
- php - php中的PHPMAILER表单验证
- artifactory - Docker 层复用
- python - Boto3 未使用 DynamoDB 加密 SDK 定位凭证
- azure-active-directory - 如何使用来自不同租户的用户登录 Azure App?
- c# - 结构是否会导致内存问题
?