Pixel Colour Replacement using C#

Posted on 2007-08-06
Last Modified: 2008-02-01
Hi all,

I am trying to do a search and replace on Pixel Colours within a bitmap in C# using the following:

for (int j = StartY; j <= StopY; j++)
   for (int i = StartX; i <= StopX; i++)
      col = bmp.GetPixel(i, j);
      if (col == Color.FromArgb(255, 255, 255)) bmp.SetPixel(i, j, Color.Red);

This works fine, but takes so long!!!!!

Are there any more efficient ways to do this?


Question by:jatkin
    LVL 96

    Accepted Solution

    Look at the iterating through pixels example here:

    Iterating through the pixels

    LVL 4

    Author Comment

    Hi Bob,

    Thanks for the reply.
    I have just managed to get what I was after using a class called "FastBitmap".

    Points well earned anyway for a fast and efficient reply..

    Best Regards,


    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    How to run any project with ease

    Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
    - Combine task lists, docs, spreadsheets, and chat in one
    - View and edit from mobile/offline
    - Cut down on emails

    Article by: Najam
    Having new technologies does not mean they will completely replace old components.  Recently I had to create WCF that will be called by VB6 component.  Here I will describe what steps one should follow while doing so, please feel free to post any qu…
    This article describes a simple method to resize a control at runtime.  It includes ready-to-use source code and a complete sample demonstration application.  We'll also talk about C# Extension Methods. Introduction In one of my applications…
    Illustrator's Shape Builder tool will let you combine shapes visually and interactively. This video shows the Mac version, but the tool works the same way in Windows. To follow along with this video, you can draw your own shapes or download the file…
    This video gives you a great overview about bandwidth monitoring with SNMP and WMI with our network monitoring solution PRTG Network Monitor ( If you're looking for how to monitor bandwidth using netflow or packet s…

    779 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    21 Experts available now in Live!

    Get 1:1 Help Now