I am new to Windows Phone * development,in my project I need to convert the pixel of image to either Red,Green,Violet,etc colors as per my requirements.Can anyone send a sample code to do this process?
It would be a great help.
Thanks.
I am new to Windows Phone * development,in my project I need to convert the pixel of image to either Red,Green,Violet,etc colors as per my requirements.Can anyone send a sample code to do this process?
It would be a great help.
Thanks.
See my solution here for converting an image to gray scale.
Convert A Dynamic Bitmap To Gray Scale.
Play attention to the loop where I decode each Red,Green,Blue pixel out of the Pixel array and where I reassemble the picture back with Buffer.BlockCopy
. So basically you can do whatever you want with those components to modify your picture then BlockCopy it back.
private void PutPixel(int x, int y, byte red, byte green, byte blue, ref WriteableBitmap wb)
{
if(wb == null)
return;
int[] PixelsBuffer = new int[1];
unchecked
{
PixelsBuffer[0] = (int)( 0xFF000000 | (int)red << 16 | (int)green << 8 | blue);
}
int offset = ((y * wb.PixelWidth) + x) * 4;
Buffer.BlockCopy(PixelsBuffer, 0, wb.Pixels, offset, 4);
}
Code In Action
<Image x:Name="myImage" Source="/Assets/AlignmentGrid.png" Stretch="None" />
// draw a white line from (0,0) to (100, 100)
private void PhoneApplicationPage_Loaded(object sender, RoutedEventArgs e)
{
WriteableBitmap wb = new WriteableBitmap((BitmapImage)this.myImage.Source);
for (int i = 0; i < 100; i++)
{
PutPixel(i, i, 0xFF, 0xFF, 0xFF, ref wb);
}
myImage.Source = wb;
}