Click here to Skip to main content
15,886,199 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
helo all,
i am new in VS2010 c# for windows phone 7.
i want to create a project to change color image to black and white (0 and 255), filtering end etc,
i found code for convert color to grayscale, here my code:

private void button2_Click(object sender, RoutedEventArgs e)
       {
           WriteableBitmap wb=new WriteableBitmap(image1, new TransformGroup());
           byte a, r, g, b, max, min;
           int pixel;
           for (int i = 0; i < wb.Pixels.Length; i++)
           {
               pixel = wb.Pixels[i];
               a = (byte)(pixel >> 24);
               r = (byte)(pixel >> 16);
               g = (byte)(pixel >> 8);
               b = (byte)pixel;
               max = Math.Max(r, g);
               max = Math.Max(max, b);
               min = Math.Min(r, g);
               min = Math.Min(min, b);
               pixel = (r + b + g) / 2;

               wb.Pixels[i] = (pixel << 24) | (pixel << 16) | (pixel << 8);

           }
           image1.Source = wb;
       }




with this code I can't get location in image (x,y),
I need to get pixel value by x,y location. some one help me please.
give me sample code please :D:D:D:D:D
sorry for my english.
Posted

See the code sample here: http://msdn.microsoft.com/en-us/library/system.windows.media.imaging.writeablebitmap.aspx[^].

You need to locate position in the buffer using the stride value.
Pay attention for this code fragment, for example:

C#
pBackBuffer += row * writeableBitmap.BackBufferStride;
pBackBuffer += column * 4;


Your row here is your Y, your column is your X.

—SA
 
Share this answer
 
Comments
bagus bujangga 22-Jun-11 6:49am    
Thanks. Its Work VERY GOOD
Sergey Alexandrovich Kryukov 22-Jun-11 10:53am    
Great, you're very welcome.
Good luck, call again.
--SA
Try the GetPixel[^] method
 
Share this answer
 
Comments
Sergey Alexandrovich Kryukov 21-Jun-11 16:18pm    
1) Should never be used due to performance (unless you need 1-3 pixels);
2) OP does not work with System.Drawing; this is WPF/Silverlight.
Sorry, I voted 1.
--SA
Dr.Walt Fair, PE 21-Jun-11 17:16pm    
Oops, I overlooked that little piece of info. Sorry about that.
I agree on the performance issue, unless you are only doing it a few times.
bagus bujangga 22-Jun-11 6:59am    
hehe, don't worry.
use my code above and SAKryukov method for fast get pixel data.
no problem use getpixel method for get pixel data for small image,
thanks for participation.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900