Click here to Skip to main content
15,889,992 members
Please Sign up or sign in to vote.
4.50/5 (2 votes)
Helo all, I need help here code c# for windows phone.
just with C# on Windows Phone 7, I can't get value of pixel in image. I was creat code for get pixel value on Windows mobile 6 using VS2008 c# and still work but very slow, here my code.

private void button2_Click(object sender, EventArgs e)
        {
            Bitmap Ori = new Bitmap(pictureBox1.Image);
            int X = Ori.Width;
            int Y = Ori.Height;
            string pesan = "Y :"+ Convert.ToString(Y)+ "X :"+  Convert.ToString(X);
            MessageBox.Show(pesan);
            for (int i = 0; i < X; i++)
            {
                for (int k = 0; k < Y; k++)
                {
                    Color pix = Ori.GetPixel(i,k);
                    byte XY = (byte)((pix.R + pix.G + pix.B) / 3);
                    pix=Color.FromArgb(XY,XY,XY);
                    Ori.SetPixel(i,k, pix);
                }
            }
            pictureBox1.Image=new Bitmap(Ori);
            
        }


this code I am copy to vs 2010 exp for windows phone and not work.
anybody know, please give me solution
1. fast getpixel on windows mobile 6 with visual studio 2008 c#
2. fast getpixel on windows phone 7 with visual studio 2010 c#

thanks before & sorry for may bad english

[edit]Code block added - OriginalGriff[/edit]
Posted
Updated 14-Jun-11 21:54pm
v2

 
Share this answer
 
Comments
Sergey Alexandrovich Kryukov 15-Jun-11 19:17pm    
Good, my 5. I just added my two cents about not using GetPixel/SetPixel, please see my solution.
--SA
bagus bujangga 15-Jun-11 20:29pm    
the code is fast on WM6, Iam use VS2008, but when I am use to VS2010 Express its not work, VS2010 say:

The type or namespace name 'BitmapData' could not be found (are you missing a using directive or an assembly reference?)

I tray to add reference
using System.Drawing.Rectangle;
using System.Drawing.Imaging.ImageLockMode;
using System.Drawing.Imaging.PixelFormat;

and VS2010 express say the same message again.
Sergey Alexandrovich Kryukov 17-Jun-11 22:56pm    
What you do in NOT ADDING REFERENCE (sorry for shouting).
"Using" does not do anything at all, it's just declares the naming of not fully qualified names. Adding reference is what you do in Solution Explorer at the References node of the project.
--SA
Never use GetPixel/SetPixel (unless you need just 1-5 of them :-)) — it's too slow!

Instead, use System.Drawing.Bitmap.LockBits methods. See:
http://msdn.microsoft.com/en-us/library/5ey6h79d.aspx[^] (see a code sample here),
http://msdn.microsoft.com/en-us/library/039882h3.aspx[^],
http://msdn.microsoft.com/en-us/library/system.drawing.bitmap.aspx[^].

—SA
 
Share this answer
 
Comments
bagus bujangga 15-Jun-11 20:33pm    
its not work, The type or namespace name 'BitmapData' could not be found (are you missing a using directive or an assembly reference?)

my be assembly reference not loaded, how to load reference??
there is no System.Drawing. while i tray to add in reference.
thanks
Sergey Alexandrovich Kryukov 17-Jun-11 22:53pm    
I don't understand it. If there is no System.Drawing, where Bitmap is declared? In your code you show Bitmap and PictureBox anyway. Look what assembly is required and add it.
--SA
Sergey Alexandrovich Kryukov 17-Jun-11 22:57pm    
Oh! I just noticed your comment to the Dave's answer: you're not adding references but you simple write "using". That's not it!
Please see my comment on adding references.
--SA

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