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

  • Home
  • SEARCH
  • 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 3789418
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 19, 20262026-05-19T12:09:14+00:00 2026-05-19T12:09:14+00:00

I was trying to create simple program that would perform some trivial operation with

  • 0

I was trying to create simple program that would perform some trivial operation with given image.
For some reason, it works only for the first time (when the app is launched):

//pseudo code

Bitmap im=Bitmap.FromFile("D:\\x.BMP");
Color [,] ColorArray=new [im.Width,im.Height];
private override voide OnPaint(EventArgs e)
{

  for(int X=0;X<im.Width;X++)
  {
      for(int Y=0;Y<im.Height;Y++)
      {
        ColorArray[X,Y]=im.GetPixel[X,Y];
      }

  }
  for(int X=0;X<im.Width;X++)
  {
      for(int Y=0;Y<im.Height;Y++)
      {
        Color c=ColorArray[X,Y];
        ...
        //some code that adds 100 to R,G,B
        im.SetPixel(X,Y,c);
      }

  }


  e.Graphics.DrawImage(im);
}
  • 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-19T12:09:15+00:00Added an answer on May 19, 2026 at 12:09 pm

    [EDIT]

    I have modified my sample code. With the previous version, it could be hard to see the difference from one iteration to the next (especially with the bmp I was using for testing). This one allows you to change color gradually by pressing 1, 2, or 3 on the Num Pad. As others have mentioned, SetPixel/GetPixel is slow, so each KeyUp event does take some time to run.

    This works fine for me.

    Create a new Windows Forms project. Drop this code in. Make sure you have “x.bmp” available. Each time you press 1, 2, or 3 on the number pad (you might need turn on Num Lock), the colors of the bitmap change slightly:

      public partial class Form1 : Form
      {
        Bitmap bm;
        Color [,] colors;
    
        public Form1()
        {
          bm = (Bitmap)Bitmap.FromFile("x.bmp");
          colors = new Color[bm.Width, bm.Height];
    
          InitializeComponent();
        }
    
        private void Form1_Paint(object sender, PaintEventArgs e)
        {
          e.Graphics.DrawImage(bm,new Point(0,0));
        }
    
        private void Form1_KeyUp(object sender, KeyEventArgs e)
        {
          //Change the colors a little bit on each KeyUp.
          //On NumPad1, change red.
          //On NumPad2, change green.
          //On NumPad3, change blue.
          //Mod with 256 to ensure a value between 0 and 255.
          int rInc = 0;
          int gInc = 0;
          int bInc = 0;
    
          switch (e.KeyCode)
          {
            case Keys.NumPad1:
              rInc = 20;
              break;
            case Keys.NumPad2:
              gInc = 20;
              break;
            case Keys.NumPad3:
              bInc = 20;
              break;
            default:
              break;
          }
    
          for (int x = 0; x < bm.Width; x++)
          {
            for (int y = 0; y < bm.Height; y++)
            {
              colors[x, y] = bm.GetPixel(x, y);
            }
          }
    
          for (int x = 0; x < bm.Width; x++)
          {
            for (int y = 0; y < bm.Height; y++)
            {
              Color c = colors[x, y];
    
              int r = (c.R + rInc) % 256;
              int g = (c.G + gInc) % 256;
              int b = (c.B + bInc) % 256;
    
              c = Color.FromArgb(255, r, g, b);
              bm.SetPixel(x, y, c);
            }
          }
    
          Invalidate();
        }
    
      }
    

    It’s not very sophisticated, but it does what you asked with real code that closely matches your pseudocode.

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

Sidebar

Related Questions

I am trying to create a simple phonebook program that reads data from a
I am trying to create a simple page that enters data in to a
I'm trying to create a message validation program and would like to create easily
I'm new to graphics programming. I'm trying to create a program that allows you
I am trying to create a very simple application (part of my learning program),
I am trying to create a simple dialog in MFC using Visual C++. My
I'm trying to create a simple BaSH-like grammar on ANTLRv3 but haven't been able
I'm trying to create a simple toggling sidebar using jquery, where it expands and
I'm playing with the ASP.NET MVC Framework, trying to create a simple site. My
I am trying to create a rather simple effect on a set of images.

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.