Skip to content

Raster that was created with NewRasterFromImage renders from Bounds.Min instead of from zero #6461

Description

@ltlaitoff

Checklist

  • I have searched the issue tracker for open issues that relate to the same problem, before opening a new one.
  • This issue only relates to a single bug. I will open new issues for any other problems.

Describe the bug

I have an image that was created with SubImage(aka a tile from a tileset for application in pixel-art style) and, because of that, Bounds().Min is actually not equal to zero

According to the Go blog: The Go image package, it's a normal situation: "A common mistake is assuming that an Image’s bounds start at (0, 0)"

But when I'm trying to render that image, after transforming it to the Raster via NewRasterFromImage, on the canvas it actually renders starting from this Bounds().Min

Expected behaviour was that the image inside the Raster renders from zero, because after that we can position it however we want on the screen, like any other CanvasObject

How to reproduce

  1. Run the code snippet

Screenshots

Image

Example code

func main() {
	application := app.NewWithID("Test image position")
	window := application.NewWindow("Test image position")

	img := image.NewRGBA(image.Rect(150, 200, 300, 400))
	bounds := img.Bounds()
	uniform := image.Uniform{C: color.RGBA{R: 0, G: 0, B: 0, A: 255}}
	draw.Draw(img, bounds, &uniform, bounds.Min, draw.Src)

	rasterImage := canvas.NewRasterFromImage(img)

	window.SetContent(rasterImage)
	window.ShowAndRun()
}

Fyne version

2.8.0

Go compiler version

1.25.0

Operating system and version

Arch Linux x86_64

Additional Information

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions