Search code examples
imagewindows-phone-7colorspixel

Load Image in writableBitmap and Convert image pixel color


How to change Image pixel color and update image in wp7 using c#

Here, I have already loaded one jpg image in img1 source. I want to load that image to writableBitmap and convert the pixel color. I have tried, but i got an empty image.

WriteableBitmap writeableBmp = new WriteableBitmap(512, 512);
writeableBmp.Render(img1, null);

for (int i = 0; i < 500; i++)
{
    writeableBmp.Pixels.SetValue(21, i);
}

img1.Source = writeableBmp;

Solution

  • You can create the Writeable Bitmap from the BitmapImage converted using JPG image.

    And then change the value and assigning to Image control is as follows .

    Please check is this solve your problem .

    BitmapImage bmp = new BitmapImage(new Uri("JpegImageUri", UriKind.RelativeOrAbsolute));
    
    WriteableBitmap wbmp = new WriteableBitmap(bmp);
    
    for (int i = 0; i < 500; i++)
    {
        wbmp.Pixels.SetValue(21, i);
    }
    
    Image image = new Image();
    image.Source = wbmp;