refactor: 注释掉绘制函数中的日志输出,以减少调试信息,保持代码整洁。
This commit is contained in:
parent
0959b16b9d
commit
56092990f0
@ -3,7 +3,6 @@ package drawhelper
|
|||||||
import (
|
import (
|
||||||
"image"
|
"image"
|
||||||
"image/color"
|
"image/color"
|
||||||
"log"
|
|
||||||
|
|
||||||
"git.lxtend.com/lixiangwuxian/imagedd/util"
|
"git.lxtend.com/lixiangwuxian/imagedd/util"
|
||||||
)
|
)
|
||||||
@ -66,7 +65,7 @@ func DrawLineOnImage(img *image.RGBA, x0, y0, x1, y1 int, color color.Color) {
|
|||||||
r8, g8, b8, a8 := uint8(r>>8), uint8(g>>8), uint8(b>>8), uint8(a>>8)
|
r8, g8, b8, a8 := uint8(r>>8), uint8(g>>8), uint8(b>>8), uint8(a>>8)
|
||||||
|
|
||||||
// 输出颜色值用于调试
|
// 输出颜色值用于调试
|
||||||
log.Printf("绘制线条: 颜色 RGBA(%d,%d,%d,%d)", r8, g8, b8, a8)
|
// log.Printf("绘制线条: 颜色 RGBA(%d,%d,%d,%d)", r8, g8, b8, a8)
|
||||||
|
|
||||||
bounds := img.Bounds()
|
bounds := img.Bounds()
|
||||||
|
|
||||||
@ -143,9 +142,9 @@ func DrawCircleOnImage(img *image.RGBA, x0, y0 int, radius float64, color color.
|
|||||||
func DrawPointIfInBounds(img *image.RGBA, bounds image.Rectangle, x, y int, r, g, b, a uint8) {
|
func DrawPointIfInBounds(img *image.RGBA, bounds image.Rectangle, x, y int, r, g, b, a uint8) {
|
||||||
if x >= bounds.Min.X && x < bounds.Max.X && y >= bounds.Min.Y && y < bounds.Max.Y {
|
if x >= bounds.Min.X && x < bounds.Max.X && y >= bounds.Min.Y && y < bounds.Max.Y {
|
||||||
// 记录绘制的像素位置和颜色,便于调试
|
// 记录绘制的像素位置和颜色,便于调试
|
||||||
if (r > 0 || g > 0 || b > 0) && a > 0 {
|
// if (r > 0 || g > 0 || b > 0) && a > 0 {
|
||||||
log.Printf("绘制像素: (%d,%d) RGBA(%d,%d,%d,%d)", x, y, r, g, b, a)
|
// log.Printf("绘制像素: (%d,%d) RGBA(%d,%d,%d,%d)", x, y, r, g, b, a)
|
||||||
}
|
// }
|
||||||
|
|
||||||
idx := (y-bounds.Min.Y)*img.Stride + (x-bounds.Min.X)*4
|
idx := (y-bounds.Min.Y)*img.Stride + (x-bounds.Min.X)*4
|
||||||
img.Pix[idx] = r
|
img.Pix[idx] = r
|
||||||
|
19
sprite/2d.go
19
sprite/2d.go
@ -4,7 +4,6 @@ import (
|
|||||||
"image"
|
"image"
|
||||||
"image/color"
|
"image/color"
|
||||||
"image/draw"
|
"image/draw"
|
||||||
"log"
|
|
||||||
|
|
||||||
"git.lxtend.com/lixiangwuxian/imagedd/drawhelper"
|
"git.lxtend.com/lixiangwuxian/imagedd/drawhelper"
|
||||||
)
|
)
|
||||||
@ -18,8 +17,8 @@ type Line struct {
|
|||||||
|
|
||||||
// AddToSprite 在精灵图上绘制线条,保留原有的图像
|
// AddToSprite 在精灵图上绘制线条,保留原有的图像
|
||||||
func (l *Line) AddToSprite(sprite *Sprite) {
|
func (l *Line) AddToSprite(sprite *Sprite) {
|
||||||
log.Printf("开始绘制线条: 起点(%d,%d) 终点(%d,%d) 宽度%d",
|
// log.Printf("开始绘制线条: 起点(%d,%d) 终点(%d,%d) 宽度%d",
|
||||||
l.Start.X, l.Start.Y, l.End.X, l.End.Y, l.Width)
|
// l.Start.X, l.Start.Y, l.End.X, l.End.Y, l.Width)
|
||||||
|
|
||||||
// 检查精灵是否已有图像
|
// 检查精灵是否已有图像
|
||||||
if sprite.Image == nil {
|
if sprite.Image == nil {
|
||||||
@ -35,15 +34,15 @@ func (l *Line) AddToSprite(sprite *Sprite) {
|
|||||||
img := image.NewRGBA(image.Rect(0, 0, width, height))
|
img := image.NewRGBA(image.Rect(0, 0, width, height))
|
||||||
sprite.Image = img
|
sprite.Image = img
|
||||||
sprite.Position = l.Start
|
sprite.Position = l.Start
|
||||||
log.Printf("创建新图像: 大小(%d,%d) 位置(%d,%d)",
|
// log.Printf("创建新图像: 大小(%d,%d) 位置(%d,%d)",
|
||||||
width, height, sprite.Position.X, sprite.Position.Y)
|
// width, height, sprite.Position.X, sprite.Position.Y)
|
||||||
}
|
}
|
||||||
|
|
||||||
// 获取当前图像大小和位置
|
// 获取当前图像大小和位置
|
||||||
bounds := sprite.Image.Bounds()
|
bounds := sprite.Image.Bounds()
|
||||||
width, height := bounds.Dx(), bounds.Dy()
|
// width, height := bounds.Dx(), bounds.Dy()
|
||||||
log.Printf("当前图像: 大小(%d,%d) 位置(%d,%d)",
|
// log.Printf("当前图像: 大小(%d,%d) 位置(%d,%d)",
|
||||||
width, height, sprite.Position.X, sprite.Position.Y)
|
// width, height, sprite.Position.X, sprite.Position.Y)
|
||||||
|
|
||||||
// 直接使用原图像,不再扩展
|
// 直接使用原图像,不再扩展
|
||||||
var newImage *image.RGBA
|
var newImage *image.RGBA
|
||||||
@ -52,7 +51,7 @@ func (l *Line) AddToSprite(sprite *Sprite) {
|
|||||||
// 如果原图像不是RGBA,转换为RGBA
|
// 如果原图像不是RGBA,转换为RGBA
|
||||||
newImage = image.NewRGBA(bounds)
|
newImage = image.NewRGBA(bounds)
|
||||||
draw.Draw(newImage, bounds, sprite.Image, bounds.Min, draw.Src)
|
draw.Draw(newImage, bounds, sprite.Image, bounds.Min, draw.Src)
|
||||||
log.Printf("转换图像为RGBA格式")
|
// log.Printf("转换图像为RGBA格式")
|
||||||
}
|
}
|
||||||
|
|
||||||
// 在图像上绘制线条,根据线宽决定使用哪个函数
|
// 在图像上绘制线条,根据线宽决定使用哪个函数
|
||||||
@ -67,7 +66,7 @@ func (l *Line) AddToSprite(sprite *Sprite) {
|
|||||||
|
|
||||||
// 更新精灵图像
|
// 更新精灵图像
|
||||||
sprite.Image = newImage
|
sprite.Image = newImage
|
||||||
log.Printf("线条绘制完成")
|
// log.Printf("线条绘制完成")
|
||||||
}
|
}
|
||||||
|
|
||||||
type Circle struct {
|
type Circle struct {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user