Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 3210576
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 17, 20262026-05-17T14:35:11+00:00 2026-05-17T14:35:11+00:00

The problem is how to invert colors of a Silverlight Image element. There is

  • 0

The problem is how to invert colors of a Silverlight Image element.

There is an Image with a JPG as a source. On a button click I need to invert the colors. Sounds simple, right. Take each pixel, then modify it’s value by 255 – pixel value. But when I tried WritableBitmap loaded with the Image source, I got security exception disallowing pixel access.
Here is my code:

            if (MainLeftImage.Source != null)
            {
                WriteableBitmap bitmap = new WriteableBitmap((BitmapSource)MainLeftImage.Source);
                byte[] pixels = new byte[bitmap.Pixels.Length];

                int size = pixels.Count();
                for (int i = 0; i < size; i++)
                    pixels[i] = (byte)(255 - pixels[i]);

                bitmap.Invalidate();//redraw and then plug it back on

                MainLeftImage.Source = bitmap;
            }
        }
        catch (Exception ex)
        {
        }

Looks that WritableBitmap is not a solution, right?
Any help appreciated. Thanks guys.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-17T14:35:11+00:00Added an answer on May 17, 2026 at 2:35 pm

    Easiest way to invert an image would be to apply a pixel shader effect. I believe that there is an invert colors pixel shader in the WPF Pixel Shader Effects Library.

    The reason that you are hitting the Security Exception is that WriteableBitmap prevents pixel access to cross-domain content. To understand why this is important, you can see my explanation of the necessity of client access policy files in this answer. To understand the point for images, just replace “secretaccountdetails.html” with “myPrivatePhoto.jpg” in the example.

    If you really want to use a WriteableBitmap to access the pixels of an Image, either:
    1. Make sure that the image source is served from the same domain as the application.
    or
    2. Make sure that the server from which the image is being served provides an appropriate client access policy and download the image file as a Stream. Use BitmapSource.SetSource(Stream) to set the source of the Image instead of setting it to the URL of the image.

    In both of the above cases you will be able to access the pixels of an Image in a WriteableBitmap.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have just started studying JOGL and there is one problem. Below is simple
I am doing a picture viewer for my website. There is a problem of
I'm facing a problem using IE here. I need to insert a form on
i am trying to make a very simple program that invert the pixels position
well my problem is, I need to find the sub matrix of a cv::Mat
I have the form below. The problem with it is that after I click
I have a little problem to insert from 2 different table's in C# to
I have a problem running an insert query via C# OleDbCommand to an Access
I have some problem whith such mysql_query INSERT INTO table VALUES ('', CURDATE()-1) why
I have a problem reading a txt file to insert in the mysql db

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.