Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

("Textures" page) ImageSharp's GetPixelSpan() appears to have been removed/replaced #39

Open
DoctorLogiq opened this issue Jun 24, 2020 · 1 comment

Comments

@DoctorLogiq
Copy link

Hi all,
Some of the information on the "Textures" page of the Learn OpenTK page may have fallen out of date, as unless my IDE (Visual Studio) is just being the usual bag of uselessness that it often is, one of the ImageSharp functions has changed.

It appears you can no longer create a byte array simply by using image.GetPixelSpan().ToArray().

Possibly related to: SixLabors/ImageSharp#1164.

@Sioma112233
Copy link

Hey, I'm also learning now using the documentation and noticed this.
I've checked the current API of ImageSharp and updated the code in my project, so until they update it, you can use it:

Image<Rgba32> image = Image.Load<Rgba32>(imagePath);
image.Mutate(x => x.Flip(FlipMode.Vertical));
			
var pixels = new List<byte>(4 * image.Width * image.Height);

for (int y = 0; y < image.Height; y++) {
	var row = image.GetPixelRowSpan(y);

	for (int x = 0; x < image.Width; x++) {
		pixels.Add(row[x].R);
		pixels.Add(row[x].G);
		pixels.Add(row[x].B);
		pixels.Add(row[x].A);
	}
}

I also gave the list constructor a capacity value because I know how big the list will be

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants