SFML community forums

Bindings - other languages => DotNet => Topic started by: rpgmaker on January 24, 2009, 05:29:14 am

Title: Image#Pixels Property does not work
Post by: rpgmaker on January 24, 2009, 05:29:14 am
When i try to retrieve the pixels for an Image, it always returns the wrong data (byte[]) which cannot be used to recreate the original image. it returns a byte array always contain data with repetition of 255s and 0s like this: 255, 255, 255, 0, 255, 255, 255.



Thanks for the help
Title: Image#Pixels Property does not work
Post by: rpgmaker on January 25, 2009, 03:18:27 am
bump
Title: Image#Pixels Property does not work
Post by: Laurent on January 25, 2009, 01:00:16 pm
Yeah yeah, I saw your post.

I'll keep you informed as soon as I can work on it.
Title: Image#Pixels Property does not work
Post by: Laurent on January 25, 2009, 03:16:04 pm
The OpenGL sample uses Image.Pixels to create an OpenGL texture, and it works fine for me. Does it work for you?
Title: Image#Pixels Property does not work
Post by: rpgmaker on January 25, 2009, 08:26:50 pm
I tried the opengl sample and it works. But i am kinda of confused why it works because any time i try to use the image#pixels to create a .net image/bitmap it fails all the time.
Title: Image#Pixels Property does not work
Post by: Laurent on January 25, 2009, 08:32:13 pm
Are you sure the problem is in Image.Pixels?

You should try to reduce your code to the minimum which reproduces the bug, and see what happens (or paste it here if you still don't know).
Title: Image#Pixels Property does not work
Post by: rpgmaker on January 25, 2009, 08:57:35 pm
I did the following:

Code: [Select]
Image img = new Image.new("file.png");
byte[] data = img.Pixels;
Stream s = new MemoryStream(data);
System.Drawing.Image dotNetImage = System.Drawing.Image.FromStream(s);// It crashes  stating  paramater is not valid
img.Dispose();
s.Close();
Title: Image#Pixels Property does not work
Post by: Laurent on January 25, 2009, 10:43:35 pm
Well, there are too many things that can fail in this piece of code. Try to remove them one by one.

For example, I would first use an hard-coded byte array instead of the pixels from the image.
Title: Image#Pixels Property does not work
Post by: rpgmaker on January 26, 2009, 12:16:13 am
After much research i figure out why it does not work. The reason was because the Image.FromStream method require a stream that contain (png, jpg, bmp file stream). My byte array did not work because it does not contain the necessary headers to be recognize as a valid image data. Thanks for the help.